diff --git a/ent/migrate/migrations/20240528220411_migration.sql b/ent/migrate/migrations/20240528220411_migration.sql index 2d49509..720e9ee 100644 --- a/ent/migrate/migrations/20240528220411_migration.sql +++ b/ent/migrate/migrations/20240528220411_migration.sql @@ -1,2 +1,2 @@ -- Modify "nodes" table -ALTER TABLE "nodes" ADD COLUMN "test_field" text NOT NULL; +ALTER TABLE "nodes" ADD COLUMN "test_field" text; diff --git a/ent/migrate/migrations/20240528221846_migration.sql b/ent/migrate/migrations/20240528221846_migration.sql new file mode 100644 index 0000000..058cb32 --- /dev/null +++ b/ent/migrate/migrations/20240528221846_migration.sql @@ -0,0 +1,2 @@ +-- Modify "nodes" table +ALTER TABLE "nodes" ALTER COLUMN "test_field" DROP NOT NULL; diff --git a/ent/migrate/migrations/atlas.sum b/ent/migrate/migrations/atlas.sum index 8b01729..3ffb5d6 100644 --- a/ent/migrate/migrations/atlas.sum +++ b/ent/migrate/migrations/atlas.sum @@ -1,3 +1,4 @@ -h1:qDiQeVaeKVjOjw5Yv9X/s3l4bU33dQ3QstZ/g8MJky0= +h1:7urIzJi6Lotk7EXEvhjHU0cLp0VVoy6dN9N099p3b2w= 20240526144817_migration.sql h1:sP6keX+oMyLL2qpIFx0Ns0WYfWM5hJ4zkFPmLWT68fM= -20240528220411_migration.sql h1:MWbTfx95zDNhc3BL0B4bSC959NKyxzLYGHxreKO9D2M= +20240528220411_migration.sql h1:SR44sOEaWbDgYCKJZIKcGCI7Ta+LqL71z225Nhs2+HM= +20240528221846_migration.sql h1:EkUonGI9Bu689qWX4pG3PRC+On4f6u7UvwDbaR8mCNk= diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go index bda4c18..e88d1a8 100644 --- a/ent/migrate/schema.go +++ b/ent/migrate/schema.go @@ -82,7 +82,7 @@ var ( {Name: "repository_url", Type: field.TypeString, SchemaType: map[string]string{"postgres": "text"}}, {Name: "icon_url", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "text"}}, {Name: "tags", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "text"}}, - {Name: "test_field", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "text"}}, + {Name: "test_field", Type: field.TypeJSON, Nullable: true, SchemaType: map[string]string{"postgres": "text"}}, {Name: "publisher_id", Type: field.TypeString, SchemaType: map[string]string{"postgres": "text"}}, } // NodesTable holds the schema information for the "nodes" table. diff --git a/ent/mutation.go b/ent/mutation.go index d2f3cb6..4ee8990 100644 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -2686,10 +2686,24 @@ func (m *NodeMutation) AppendedTestField() ([]string, bool) { return m.appendtest_field, true } +// ClearTestField clears the value of the "test_field" field. +func (m *NodeMutation) ClearTestField() { + m.test_field = nil + m.appendtest_field = nil + m.clearedFields[node.FieldTestField] = struct{}{} +} + +// TestFieldCleared returns if the "test_field" field was cleared in this mutation. +func (m *NodeMutation) TestFieldCleared() bool { + _, ok := m.clearedFields[node.FieldTestField] + return ok +} + // ResetTestField resets all changes to the "test_field" field. func (m *NodeMutation) ResetTestField() { m.test_field = nil m.appendtest_field = nil + delete(m.clearedFields, node.FieldTestField) } // ClearPublisher clears the "publisher" edge to the Publisher entity. @@ -3027,6 +3041,9 @@ func (m *NodeMutation) ClearedFields() []string { if m.FieldCleared(node.FieldIconURL) { fields = append(fields, node.FieldIconURL) } + if m.FieldCleared(node.FieldTestField) { + fields = append(fields, node.FieldTestField) + } return fields } @@ -3050,6 +3067,9 @@ func (m *NodeMutation) ClearField(name string) error { case node.FieldIconURL: m.ClearIconURL() return nil + case node.FieldTestField: + m.ClearTestField() + return nil } return fmt.Errorf("unknown Node nullable field %s", name) } diff --git a/ent/node/where.go b/ent/node/where.go index 6260d08..b765bd7 100644 --- a/ent/node/where.go +++ b/ent/node/where.go @@ -675,6 +675,16 @@ func IconURLContainsFold(v string) predicate.Node { return predicate.Node(sql.FieldContainsFold(FieldIconURL, v)) } +// TestFieldIsNil applies the IsNil predicate on the "test_field" field. +func TestFieldIsNil() predicate.Node { + return predicate.Node(sql.FieldIsNull(FieldTestField)) +} + +// TestFieldNotNil applies the NotNil predicate on the "test_field" field. +func TestFieldNotNil() predicate.Node { + return predicate.Node(sql.FieldNotNull(FieldTestField)) +} + // HasPublisher applies the HasEdge predicate on the "publisher" edge. func HasPublisher() predicate.Node { return predicate.Node(func(s *sql.Selector) { diff --git a/ent/node_create.go b/ent/node_create.go index b3e271c..21ba95d 100644 --- a/ent/node_create.go +++ b/ent/node_create.go @@ -234,9 +234,6 @@ func (nc *NodeCreate) check() error { if _, ok := nc.mutation.Tags(); !ok { return &ValidationError{Name: "tags", err: errors.New(`ent: missing required field "Node.tags"`)} } - if _, ok := nc.mutation.TestField(); !ok { - return &ValidationError{Name: "test_field", err: errors.New(`ent: missing required field "Node.test_field"`)} - } if _, ok := nc.mutation.PublisherID(); !ok { return &ValidationError{Name: "publisher", err: errors.New(`ent: missing required edge "Node.publisher"`)} } @@ -539,6 +536,12 @@ func (u *NodeUpsert) UpdateTestField() *NodeUpsert { return u } +// ClearTestField clears the value of the "test_field" field. +func (u *NodeUpsert) ClearTestField() *NodeUpsert { + u.SetNull(node.FieldTestField) + return u +} + // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. // Using this option is equivalent to using: // @@ -751,6 +754,13 @@ func (u *NodeUpsertOne) UpdateTestField() *NodeUpsertOne { }) } +// ClearTestField clears the value of the "test_field" field. +func (u *NodeUpsertOne) ClearTestField() *NodeUpsertOne { + return u.Update(func(s *NodeUpsert) { + s.ClearTestField() + }) +} + // Exec executes the query. func (u *NodeUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { @@ -1130,6 +1140,13 @@ func (u *NodeUpsertBulk) UpdateTestField() *NodeUpsertBulk { }) } +// ClearTestField clears the value of the "test_field" field. +func (u *NodeUpsertBulk) ClearTestField() *NodeUpsertBulk { + return u.Update(func(s *NodeUpsert) { + s.ClearTestField() + }) +} + // Exec executes the query. func (u *NodeUpsertBulk) Exec(ctx context.Context) error { if u.create.err != nil { diff --git a/ent/node_update.go b/ent/node_update.go index 8b4e169..8577d6c 100644 --- a/ent/node_update.go +++ b/ent/node_update.go @@ -178,6 +178,12 @@ func (nu *NodeUpdate) AppendTestField(s []string) *NodeUpdate { return nu } +// ClearTestField clears the value of the "test_field" field. +func (nu *NodeUpdate) ClearTestField() *NodeUpdate { + nu.mutation.ClearTestField() + return nu +} + // SetPublisher sets the "publisher" edge to the Publisher entity. func (nu *NodeUpdate) SetPublisher(p *Publisher) *NodeUpdate { return nu.SetPublisherID(p.ID) @@ -332,6 +338,9 @@ func (nu *NodeUpdate) sqlSave(ctx context.Context) (n int, err error) { sqljson.Append(u, node.FieldTestField, value) }) } + if nu.mutation.TestFieldCleared() { + _spec.ClearField(node.FieldTestField, field.TypeJSON) + } if nu.mutation.PublisherCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -572,6 +581,12 @@ func (nuo *NodeUpdateOne) AppendTestField(s []string) *NodeUpdateOne { return nuo } +// ClearTestField clears the value of the "test_field" field. +func (nuo *NodeUpdateOne) ClearTestField() *NodeUpdateOne { + nuo.mutation.ClearTestField() + return nuo +} + // SetPublisher sets the "publisher" edge to the Publisher entity. func (nuo *NodeUpdateOne) SetPublisher(p *Publisher) *NodeUpdateOne { return nuo.SetPublisherID(p.ID) @@ -756,6 +771,9 @@ func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (_node *Node, err error) sqljson.Append(u, node.FieldTestField, value) }) } + if nuo.mutation.TestFieldCleared() { + _spec.ClearField(node.FieldTestField, field.TypeJSON) + } if nuo.mutation.PublisherCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/ent/schema/node.go b/ent/schema/node.go index 9a74694..0974d1d 100644 --- a/ent/schema/node.go +++ b/ent/schema/node.go @@ -45,7 +45,7 @@ func (Node) Fields() []ent.Field { }).Default([]string{}), field.Strings("test_field").SchemaType(map[string]string{ dialect.Postgres: "text", - }).Default([]string{}), + }).Default([]string{}).Optional(), } }