Skip to content

Commit

Permalink
db: init memo and memo relation schema
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
zwpaper committed Feb 8, 2024
1 parent 60efd3a commit c764867
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ent/schema/memo.go
Original file line number Diff line number Diff line change
@@ -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),
}
}
35 changes: 35 additions & 0 deletions ent/schema/memorelation.go
Original file line number Diff line number Diff line change
@@ -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"),
}
}

0 comments on commit c764867

Please sign in to comment.