rano/db/ent/schema/audit.go

42 lines
914 B
Go
Raw Normal View History

2024-11-10 09:22:33 +00:00
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// Audit holds the schema definition for the Audit entity.
type Audit struct {
ent.Schema
}
// Fields of the Audit.
func (Audit) Fields() []ent.Field {
return []ent.Field{
fieldID,
fieldCreated,
field.String("ent_name").MaxLen(50),
field.Int64("ent_id").Positive(),
field.Enum("operation").Values("Create", "Update", "UpdateOne", "Delete", "DeleteOne"),
field.String("description").MaxLen(1000),
field.String("ip").MaxLen(40).Optional(),
field.String("user_name").MaxLen(150).Optional(),
}
}
func (Audit) Indexes() []ent.Index {
return []ent.Index{
index.Fields("ent_name", "ent_id"),
index.Fields("operation"),
index.Fields("ip"),
}
}
func (Audit) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).Ref("audit_logs").Unique(),
}
}