diff --git a/.golangci.yml b/.golangci.yml index 5647c2673..ceb8f6c42 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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. diff --git a/dialect/entsql/annotation.go b/dialect/entsql/annotation.go index 8ad195067..57244153b 100644 --- a/dialect/entsql/annotation.go +++ b/dialect/entsql/annotation.go @@ -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 } diff --git a/entc/gen/graph.go b/entc/gen/graph.go index c2fffad03..3f744f799 100644 --- a/entc/gen/graph.go +++ b/entc/gen/graph.go @@ -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()) }