55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package schema
|
|
|
|
import (
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/index"
|
|
)
|
|
|
|
// PostContent holds the schema definition for the PostContent entity.
|
|
type PostContent struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Fields of the PostContent.
|
|
func (PostContent) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Enum("language_code").
|
|
NamedValues(
|
|
"EN", "en",
|
|
"ZH_HANS", "zh-Hans",
|
|
"ZH_HANT", "zh-Hant",
|
|
),
|
|
field.String("title").
|
|
NotEmpty(),
|
|
field.Text("content_markdown").
|
|
NotEmpty(),
|
|
field.String("summary").
|
|
NotEmpty(),
|
|
field.String("meta_keywords").
|
|
Optional(),
|
|
field.String("meta_description").
|
|
Optional(),
|
|
field.String("slug").
|
|
NotEmpty(),
|
|
}
|
|
}
|
|
|
|
// Edges of the PostContent.
|
|
func (PostContent) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("post", Post.Type).
|
|
Ref("contents").
|
|
Unique(),
|
|
}
|
|
}
|
|
|
|
// Indexes of the PostContent.
|
|
func (PostContent) Indexes() []ent.Index {
|
|
return []ent.Index{
|
|
index.Fields("language_code").
|
|
Edges("post").
|
|
Unique(),
|
|
}
|
|
}
|