dialect/sql/schema: normalize ent/schema (desired state) on replay mode (#3100)

This commit is contained in:
Ariel Mashraki
2022-11-16 20:01:36 +02:00
committed by GitHub
parent cd60f84853
commit 5954fa8b15
8 changed files with 186 additions and 75 deletions

View File

@@ -33,7 +33,7 @@ var (
func init() {
UsersTable.Annotation = &entsql.Annotation{
Check: "(`age` > 0)",
Check: "age > 0",
}
UsersTable.Annotation.Checks = map[string]string{
"name_not_empty": "name <> ''",

View File

@@ -23,9 +23,10 @@ func (User) Fields() []ent.Field {
// Annotations of the User.
func (User) Annotations() []schema.Annotation {
return []schema.Annotation{
// Unnamed check constraints should be identical to their definition in the
// database (i.e. normalized). See: https://atlasgo.io/concepts/dev-database.
entsql.Check("(`age` > 0)"),
// In case schema.ModeInspect is used without a dev-database, unnamed check constraints
// should be normalized (i.e. identical to their definition in the database). In this
// case, it is entsql.Check("(`age` > 0)"). See: https://atlasgo.io/concepts/dev-database.
entsql.Check("age > 0"),
// Named check constraints are compared by their name.
// Thus, the definition does not need to be normalized.