8000 Add the ability to enforce adding table columns in user defined order by sjpotter · Pull Request #4389 · ent/ent · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add the ability to enforce adding table columns in user defined order #4389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dialect/entsql/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ type Annotation struct {
// }
ViewFor map[string]string `json:"view_for,omitempty"`

// TableFieldOrder tells ent to use the user provided Field order for columns,
// and to not push all Edges till the end of the column list
TableFieldOrder bool `json:"table_field_order,omitempty"`

// error occurs during annotation build. This field is not
// serialized to JSON and used only by the codegen loader.
err error
Expand Down Expand Up @@ -299,6 +303,10 @@ func ViewFor(dialect string, as func(*sql.Selector)) *Annotation {
}
}

func TableFieldOrder() *Annotation {
return &Annotation{TableFieldOrder: true}
}

// Default specifies a literal default value of a column. Note that using
// this option overrides the default behavior of the code-generation.
//
Expand Down
3 changes: 2 additions & 1 deletion entc/gen/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,12 @@ func (g *Graph) Tables() (all []*schema.Table, err error) {
default:
table.SetAnnotation(ant).SetSchema(ant.Schema)
}
nAnt := n.EntSQL()
for _, f := range n.Fields {
if a := f.EntSQL(); a != nil && a.Skip {
continue
}
if !f.IsEdgeField() {
if (nAnt != nil && nAnt.TableFieldOrder) || !f.IsEdgeField() {
table.AddColumn(f.Column())
}
}
Expand Down
0