first commit
This commit is contained in:
32
backend/ent/schema/mixins/time.go
Normal file
32
backend/ent/schema/mixins/time.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package mixins
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
)
|
||||
|
||||
// TimeMixin provides created_at and updated_at fields compatible with the existing schema.
|
||||
type TimeMixin struct {
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
func (TimeMixin) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Time("created_at").
|
||||
Immutable().
|
||||
Default(time.Now).
|
||||
SchemaType(map[string]string{
|
||||
dialect.Postgres: "timestamptz",
|
||||
}),
|
||||
field.Time("updated_at").
|
||||
Default(time.Now).
|
||||
UpdateDefault(time.Now).
|
||||
SchemaType(map[string]string{
|
||||
dialect.Postgres: "timestamptz",
|
||||
}),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user