orm: correct behavior of created_at, updated_at, define immutable fields
This commit is contained in:
parent
05b54687b6
commit
142108529d
8 changed files with 19 additions and 19 deletions
|
@ -19,10 +19,10 @@ func (Alert) Fields() []ent.Field {
|
|||
return []ent.Field{
|
||||
field.Time("created_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
Immutable(),
|
||||
field.Time("updated_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
UpdateDefault(types.UtcNow),
|
||||
field.String("scenario"),
|
||||
field.String("bucketId").Default("").Optional(),
|
||||
field.String("message").Default("").Optional(),
|
||||
|
|
|
@ -16,10 +16,10 @@ func (Bouncer) Fields() []ent.Field {
|
|||
return []ent.Field{
|
||||
field.Time("created_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional().StructTag(`json:"created_at"`),
|
||||
StructTag(`json:"created_at"`),
|
||||
field.Time("updated_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional().StructTag(`json:"updated_at"`),
|
||||
UpdateDefault(types.UtcNow).StructTag(`json:"updated_at"`),
|
||||
field.String("name").Unique().StructTag(`json:"name"`),
|
||||
field.String("api_key").Sensitive(), // hash of api_key
|
||||
field.Bool("revoked").StructTag(`json:"revoked"`),
|
||||
|
|
|
@ -11,21 +11,20 @@ type ConfigItem struct {
|
|||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Bouncer.
|
||||
func (ConfigItem) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Time("created_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional().StructTag(`json:"created_at"`),
|
||||
Immutable().
|
||||
StructTag(`json:"created_at"`),
|
||||
field.Time("updated_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional().StructTag(`json:"updated_at"`),
|
||||
UpdateDefault(types.UtcNow).StructTag(`json:"updated_at"`),
|
||||
field.String("name").Unique().StructTag(`json:"name"`),
|
||||
field.String("value").StructTag(`json:"value"`), // a json object
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Bouncer.
|
||||
func (ConfigItem) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@ func (Decision) Fields() []ent.Field {
|
|||
return []ent.Field{
|
||||
field.Time("created_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
Immutable(),
|
||||
field.Time("updated_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
UpdateDefault(types.UtcNow),
|
||||
field.Time("until").Nillable().Optional().SchemaType(map[string]string{
|
||||
dialect.MySQL: "datetime",
|
||||
}),
|
||||
|
|
|
@ -18,10 +18,10 @@ func (Event) Fields() []ent.Field {
|
|||
return []ent.Field{
|
||||
field.Time("created_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
Immutable(),
|
||||
field.Time("updated_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
UpdateDefault(types.UtcNow),
|
||||
field.Time("time"),
|
||||
field.String("serialized").MaxLen(8191),
|
||||
field.Int("alert_events").Optional(),
|
||||
|
|
|
@ -12,7 +12,7 @@ type Lock struct {
|
|||
|
||||
func (Lock) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").Unique().StructTag(`json:"name"`),
|
||||
field.String("name").Unique().Immutable().StructTag(`json:"name"`),
|
||||
field.Time("created_at").Default(types.UtcNow).StructTag(`json:"created_at"`),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,17 +17,19 @@ func (Machine) Fields() []ent.Field {
|
|||
return []ent.Field{
|
||||
field.Time("created_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
Immutable(),
|
||||
field.Time("updated_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
UpdateDefault(types.UtcNow),
|
||||
field.Time("last_push").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
field.Time("last_heartbeat").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
field.String("machineId").Unique(),
|
||||
field.String("machineId").
|
||||
Unique().
|
||||
Immutable(),
|
||||
field.String("password").Sensitive(),
|
||||
field.String("ipAddress"),
|
||||
field.String("scenarios").MaxLen(100000).Optional(),
|
||||
|
|
|
@ -17,11 +17,10 @@ type Meta struct {
|
|||
func (Meta) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Time("created_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
Default(types.UtcNow),
|
||||
field.Time("updated_at").
|
||||
Default(types.UtcNow).
|
||||
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
||||
UpdateDefault(types.UtcNow),
|
||||
field.String("key"),
|
||||
field.String("value").MaxLen(4095),
|
||||
field.Int("alert_metas").Optional(),
|
||||
|
|
Loading…
Reference in a new issue