Skip to content

Commit 942f7ae

Browse files
authored
Merge pull request #22 from database-playground/category-must-not-be-unique
fix(ent): question > category should not be unique and immutable
2 parents 9f3368c + 41df807 commit 942f7ae

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

ent/gql_mutation_input.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/internal/schema.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/migrate/schema.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/question_update.go

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/schema/question.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"entgo.io/ent/schema"
77
"entgo.io/ent/schema/edge"
88
"entgo.io/ent/schema/field"
9+
"entgo.io/ent/schema/index"
910
)
1011

1112
type Question struct {
@@ -14,7 +15,7 @@ type Question struct {
1415

1516
func (Question) Fields() []ent.Field {
1617
return []ent.Field{
17-
field.String("category").NotEmpty().Unique().Immutable().Comment("Question category, e.g. 'query'").Annotations(
18+
field.String("category").NotEmpty().Comment("Question category, e.g. 'query'").Annotations(
1819
entgql.OrderField("CATEGORY"),
1920
),
2021
field.Enum("difficulty").NamedValues(
@@ -48,6 +49,13 @@ func (Question) Edges() []ent.Edge {
4849
}
4950
}
5051

52+
func (Question) Indexes() []ent.Index {
53+
return []ent.Index{
54+
index.Fields("category"),
55+
index.Fields("difficulty"),
56+
}
57+
}
58+
5159
func (Question) Annotations() []schema.Annotation {
5260
return []schema.Annotation{
5361
entgql.QueryField().Directives(

graph/ent.graphqls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,10 @@ UpdateQuestionInput is used for update Question object.
12241224
Input was generated by ent.
12251225
"""
12261226
input UpdateQuestionInput {
1227+
"""
1228+
Question category, e.g. 'query'
1229+
"""
1230+
category: String
12271231
"""
12281232
Question difficulty, e.g. 'easy'
12291233
"""

0 commit comments

Comments
 (0)