dialect/entsql: add Skip annotation (#4156)

This commit is contained in:
Ariel Mashraki
2024-07-26 23:03:21 +03:00
committed by GitHub
parent be9aafdc49
commit 5cd2ede22d
3 changed files with 28 additions and 4 deletions

View File

@@ -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.

View File

@@ -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
}

View File

@@ -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())
}