dialect/sql/schema: allow setting table comments (#3365)

This commit is contained in:
Ariel Mashraki
2023-03-04 20:50:26 +02:00
committed by GitHub
parent f16451eab8
commit 3b7715b552
11 changed files with 55 additions and 9 deletions

View File

@@ -872,6 +872,9 @@ func (a *Atlas) tables(tables []*Table) ([]*schema.Table, error) {
ts := make([]*schema.Table, len(tables))
for i, et := range tables {
at := schema.NewTable(et.Name)
if et.Comment != "" {
at.SetComment(et.Comment)
}
a.sqlDialect.atTable(et, at)
if a.universalID && et.Name != TypeTable && len(et.PrimaryKey) == 1 {
r, err := a.pkRange(et)

View File

@@ -36,6 +36,7 @@ type Table struct {
PrimaryKey []*Column
ForeignKeys []*ForeignKey
Annotation *entsql.Annotation
Comment string
}
// NewTable returns a new table with the given name.
@@ -46,6 +47,12 @@ func NewTable(name string) *Table {
}
}
// SetComment sets the table comment.
func (t *Table) SetComment(c string) *Table {
t.Comment = c
return t
}
// AddPrimary adds a new primary key to the table.
func (t *Table) AddPrimary(c *Column) *Table {
c.Key = PrimaryKey
@@ -295,7 +302,7 @@ type Column struct {
typ string // row column type (used for Rows.Scan).
indexes Indexes // linked indexes.
foreign *ForeignKey // linked foreign-key.
Comment string // column comment.
Comment string // optional column comment.
}
// Expr represents a raw expression. It is used to distinguish between