dialect/entsql: add support for column default using annotation

Fixed #1033
This commit is contained in:
Ariel Mashraki
2021-04-02 17:10:00 +03:00
committed by Ariel Mashraki
parent 3db3f5fd1a
commit 745afde770
16 changed files with 319 additions and 30 deletions

View File

@@ -5,7 +5,10 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
@@ -80,6 +83,12 @@ func (User) Fields() []ent.Field {
// remove the max-length constraint from varchar.
field.String("workplace").
Optional(),
// add a new column with generated values by the database.
field.Time("created_at").
Default(time.Now).
Annotations(&entsql.Annotation{
Default: "CURRENT_TIMESTAMP",
}),
// deleting the `address` column.
}
}