mirror of
https://github.com/ent/ent.git
synced 2026-03-05 19:35:23 +03:00
dialect/entsql: add Skip annotation (#4156)
This commit is contained in:
@@ -8,8 +8,8 @@ linters-settings:
|
||||
dupl:
|
||||
threshold: 100
|
||||
funlen:
|
||||
lines: 140
|
||||
statements: 140
|
||||
lines: 200
|
||||
statements: 200
|
||||
goheader:
|
||||
template: |-
|
||||
Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
|
||||
@@ -149,6 +149,15 @@ type Annotation struct {
|
||||
// }
|
||||
//
|
||||
Checks map[string]string `json:"checks,omitempty"`
|
||||
|
||||
// Skip indicates that the field or the schema is skipped/ignored during
|
||||
// migration (e.g., defined externally).
|
||||
//
|
||||
// entsql.Annotation{
|
||||
// Skip: true,
|
||||
// }
|
||||
//
|
||||
Skip bool `json:"skip,omitempty"`
|
||||
}
|
||||
|
||||
// Name describes the annotation name.
|
||||
@@ -217,6 +226,12 @@ func Checks(c map[string]string) *Annotation {
|
||||
}
|
||||
}
|
||||
|
||||
// Skip indicates that the field or the schema is skipped/ignored during
|
||||
// migration (e.g., defined externally).
|
||||
func Skip() *Annotation {
|
||||
return &Annotation{Skip: true}
|
||||
}
|
||||
|
||||
// Default specifies a literal default value of a column. Note that using
|
||||
// this option overrides the default behavior of the code-generation.
|
||||
//
|
||||
@@ -358,6 +373,9 @@ func (a Annotation) Merge(other schema.Annotation) schema.Annotation {
|
||||
a.Checks[name] = check
|
||||
}
|
||||
}
|
||||
if ant.Skip {
|
||||
a.Skip = true
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
|
||||
@@ -623,11 +623,17 @@ func (g *Graph) Tables() (all []*schema.Table, err error) {
|
||||
if n.HasOneFieldID() {
|
||||
table.AddPrimary(n.ID.PK())
|
||||
}
|
||||
ant := n.EntSQL()
|
||||
if ant != nil {
|
||||
switch ant := n.EntSQL(); {
|
||||
case ant == nil:
|
||||
case ant.Skip:
|
||||
continue
|
||||
default:
|
||||
table.SetAnnotation(ant).SetSchema(ant.Schema)
|
||||
}
|
||||
for _, f := range n.Fields {
|
||||
if a := f.EntSQL(); a != nil && a.Skip {
|
||||
continue
|
||||
}
|
||||
if !f.IsEdgeField() {
|
||||
table.AddColumn(f.Column())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user