time.go 632 B

1234567891011121314151617181920212223242526272829303132
  1. package mixins
  2. import (
  3. "time"
  4. "entgo.io/ent"
  5. "entgo.io/ent/dialect"
  6. "entgo.io/ent/schema/field"
  7. "entgo.io/ent/schema/mixin"
  8. )
  9. // TimeMixin provides created_at and updated_at fields compatible with the existing schema.
  10. type TimeMixin struct {
  11. mixin.Schema
  12. }
  13. func (TimeMixin) Fields() []ent.Field {
  14. return []ent.Field{
  15. field.Time("created_at").
  16. Immutable().
  17. Default(time.Now).
  18. SchemaType(map[string]string{
  19. dialect.Postgres: "timestamptz",
  20. }),
  21. field.Time("updated_at").
  22. Default(time.Now).
  23. UpdateDefault(time.Now).
  24. SchemaType(map[string]string{
  25. dialect.Postgres: "timestamptz",
  26. }),
  27. }
  28. }