-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
db: init memo and memo relation schema
Signed-off-by: Wei Zhang <[email protected]>
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
} | ||
} |