33 lines
632 B
Go
33 lines
632 B
Go
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",
|
|
}),
|
|
}
|
|
}
|