From c7648670c839539ef94a4af9d15546de34929aa4 Mon Sep 17 00:00:00 2001 From: Wei Zhang Date: Thu, 8 Feb 2024 23:06:59 +0800 Subject: [PATCH] db: init memo and memo relation schema Signed-off-by: Wei Zhang --- ent/schema/memo.go | 34 ++++++++++++++++++++++++++++++++++ ent/schema/memorelation.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 ent/schema/memo.go create mode 100644 ent/schema/memorelation.go diff --git a/ent/schema/memo.go b/ent/schema/memo.go new file mode 100644 index 0000000000000..22523d4f63b3f --- /dev/null +++ b/ent/schema/memo.go @@ -0,0 +1,34 @@ +package schema + +import ( + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" +) + +// Memo holds the schema definition for the Memo entity. +type Memo struct { + ent.Schema +} + +// Fields of the Memo. +func (Memo) Fields() []ent.Field { + return []ent.Field{ + field.Int("id").Positive(), + field.String("resource_name").MaxLen(256).NotEmpty().Unique(), + field.Int("creator_id").Positive(), + field.Time("created_ts"), + field.Time("updated_ts"), + field.String("row_status").MaxLen(256).NotEmpty(), + field.Text("content").Default(""), + field.String("visibility").MaxLen(256).NotEmpty(), + } +} + +// Edges of the Memo. +func (Memo) Edges() []ent.Edge { + return []ent.Edge{ + edge.To("related_memo", Memo.Type). + Through("memo_relation", MemoRelation.Type), + } +} diff --git a/ent/schema/memorelation.go b/ent/schema/memorelation.go new file mode 100644 index 0000000000000..0dbb7fd7907a9 --- /dev/null +++ b/ent/schema/memorelation.go @@ -0,0 +1,35 @@ +package schema + +import ( + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" +) + +// MemoRelation holds the schema definition for the MemoRelation entity. +type MemoRelation struct { + ent.Schema +} + +// Fields of the MemoRelation. +func (MemoRelation) Fields() []ent.Field { + return []ent.Field{ + field.String("type"), + field.Int("memo_id"), + field.Int("related_memo_id"), + } +} + +// Edges of the MemoRelation. +func (MemoRelation) Edges() []ent.Edge { + return []ent.Edge{ + edge.To("memo", Memo.Type). + Required(). + Unique(). + Field("memo_id"), + edge.To("related_memo", Memo.Type). + Required(). + Unique(). + Field("related_memo_id"), + } +}