boweniac 7 months ago
parent
commit
3e57efb0e7
6 changed files with 154 additions and 10 deletions
  1. 20 0
      ent/agent/where.go
  2. 56 6
      ent/agent_create.go
  3. 36 0
      ent/agent_update.go
  4. 2 2
      ent/migrate/schema.go
  5. 38 0
      ent/mutation.go
  6. 2 2
      ent/schema/agent.go

+ 20 - 0
ent/agent/where.go

@@ -465,6 +465,16 @@ func BackgroundHasSuffix(v string) predicate.Agent {
 	return predicate.Agent(sql.FieldHasSuffix(FieldBackground, v))
 }
 
+// BackgroundIsNil applies the IsNil predicate on the "background" field.
+func BackgroundIsNil() predicate.Agent {
+	return predicate.Agent(sql.FieldIsNull(FieldBackground))
+}
+
+// BackgroundNotNil applies the NotNil predicate on the "background" field.
+func BackgroundNotNil() predicate.Agent {
+	return predicate.Agent(sql.FieldNotNull(FieldBackground))
+}
+
 // BackgroundEqualFold applies the EqualFold predicate on the "background" field.
 func BackgroundEqualFold(v string) predicate.Agent {
 	return predicate.Agent(sql.FieldEqualFold(FieldBackground, v))
@@ -530,6 +540,16 @@ func ExamplesHasSuffix(v string) predicate.Agent {
 	return predicate.Agent(sql.FieldHasSuffix(FieldExamples, v))
 }
 
+// ExamplesIsNil applies the IsNil predicate on the "examples" field.
+func ExamplesIsNil() predicate.Agent {
+	return predicate.Agent(sql.FieldIsNull(FieldExamples))
+}
+
+// ExamplesNotNil applies the NotNil predicate on the "examples" field.
+func ExamplesNotNil() predicate.Agent {
+	return predicate.Agent(sql.FieldNotNull(FieldExamples))
+}
+
 // ExamplesEqualFold applies the EqualFold predicate on the "examples" field.
 func ExamplesEqualFold(v string) predicate.Agent {
 	return predicate.Agent(sql.FieldEqualFold(FieldExamples, v))

+ 56 - 6
ent/agent_create.go

@@ -97,12 +97,28 @@ func (ac *AgentCreate) SetBackground(s string) *AgentCreate {
 	return ac
 }
 
+// SetNillableBackground sets the "background" field if the given value is not nil.
+func (ac *AgentCreate) SetNillableBackground(s *string) *AgentCreate {
+	if s != nil {
+		ac.SetBackground(*s)
+	}
+	return ac
+}
+
 // SetExamples sets the "examples" field.
 func (ac *AgentCreate) SetExamples(s string) *AgentCreate {
 	ac.mutation.SetExamples(s)
 	return ac
 }
 
+// SetNillableExamples sets the "examples" field if the given value is not nil.
+func (ac *AgentCreate) SetNillableExamples(s *string) *AgentCreate {
+	if s != nil {
+		ac.SetExamples(*s)
+	}
+	return ac
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (ac *AgentCreate) SetOrganizationID(u uint64) *AgentCreate {
 	ac.mutation.SetOrganizationID(u)
@@ -217,17 +233,11 @@ func (ac *AgentCreate) check() error {
 			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
 		}
 	}
-	if _, ok := ac.mutation.Background(); !ok {
-		return &ValidationError{Name: "background", err: errors.New(`ent: missing required field "Agent.background"`)}
-	}
 	if v, ok := ac.mutation.Background(); ok {
 		if err := agent.BackgroundValidator(v); err != nil {
 			return &ValidationError{Name: "background", err: fmt.Errorf(`ent: validator failed for field "Agent.background": %w`, err)}
 		}
 	}
-	if _, ok := ac.mutation.Examples(); !ok {
-		return &ValidationError{Name: "examples", err: errors.New(`ent: missing required field "Agent.examples"`)}
-	}
 	if v, ok := ac.mutation.Examples(); ok {
 		if err := agent.ExamplesValidator(v); err != nil {
 			return &ValidationError{Name: "examples", err: fmt.Errorf(`ent: validator failed for field "Agent.examples": %w`, err)}
@@ -468,6 +478,12 @@ func (u *AgentUpsert) UpdateBackground() *AgentUpsert {
 	return u
 }
 
+// ClearBackground clears the value of the "background" field.
+func (u *AgentUpsert) ClearBackground() *AgentUpsert {
+	u.SetNull(agent.FieldBackground)
+	return u
+}
+
 // SetExamples sets the "examples" field.
 func (u *AgentUpsert) SetExamples(v string) *AgentUpsert {
 	u.Set(agent.FieldExamples, v)
@@ -480,6 +496,12 @@ func (u *AgentUpsert) UpdateExamples() *AgentUpsert {
 	return u
 }
 
+// ClearExamples clears the value of the "examples" field.
+func (u *AgentUpsert) ClearExamples() *AgentUpsert {
+	u.SetNull(agent.FieldExamples)
+	return u
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (u *AgentUpsert) SetOrganizationID(v uint64) *AgentUpsert {
 	u.Set(agent.FieldOrganizationID, v)
@@ -654,6 +676,13 @@ func (u *AgentUpsertOne) UpdateBackground() *AgentUpsertOne {
 	})
 }
 
+// ClearBackground clears the value of the "background" field.
+func (u *AgentUpsertOne) ClearBackground() *AgentUpsertOne {
+	return u.Update(func(s *AgentUpsert) {
+		s.ClearBackground()
+	})
+}
+
 // SetExamples sets the "examples" field.
 func (u *AgentUpsertOne) SetExamples(v string) *AgentUpsertOne {
 	return u.Update(func(s *AgentUpsert) {
@@ -668,6 +697,13 @@ func (u *AgentUpsertOne) UpdateExamples() *AgentUpsertOne {
 	})
 }
 
+// ClearExamples clears the value of the "examples" field.
+func (u *AgentUpsertOne) ClearExamples() *AgentUpsertOne {
+	return u.Update(func(s *AgentUpsert) {
+		s.ClearExamples()
+	})
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (u *AgentUpsertOne) SetOrganizationID(v uint64) *AgentUpsertOne {
 	return u.Update(func(s *AgentUpsert) {
@@ -1011,6 +1047,13 @@ func (u *AgentUpsertBulk) UpdateBackground() *AgentUpsertBulk {
 	})
 }
 
+// ClearBackground clears the value of the "background" field.
+func (u *AgentUpsertBulk) ClearBackground() *AgentUpsertBulk {
+	return u.Update(func(s *AgentUpsert) {
+		s.ClearBackground()
+	})
+}
+
 // SetExamples sets the "examples" field.
 func (u *AgentUpsertBulk) SetExamples(v string) *AgentUpsertBulk {
 	return u.Update(func(s *AgentUpsert) {
@@ -1025,6 +1068,13 @@ func (u *AgentUpsertBulk) UpdateExamples() *AgentUpsertBulk {
 	})
 }
 
+// ClearExamples clears the value of the "examples" field.
+func (u *AgentUpsertBulk) ClearExamples() *AgentUpsertBulk {
+	return u.Update(func(s *AgentUpsert) {
+		s.ClearExamples()
+	})
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (u *AgentUpsertBulk) SetOrganizationID(v uint64) *AgentUpsertBulk {
 	return u.Update(func(s *AgentUpsert) {

+ 36 - 0
ent/agent_update.go

@@ -124,6 +124,12 @@ func (au *AgentUpdate) SetNillableBackground(s *string) *AgentUpdate {
 	return au
 }
 
+// ClearBackground clears the value of the "background" field.
+func (au *AgentUpdate) ClearBackground() *AgentUpdate {
+	au.mutation.ClearBackground()
+	return au
+}
+
 // SetExamples sets the "examples" field.
 func (au *AgentUpdate) SetExamples(s string) *AgentUpdate {
 	au.mutation.SetExamples(s)
@@ -138,6 +144,12 @@ func (au *AgentUpdate) SetNillableExamples(s *string) *AgentUpdate {
 	return au
 }
 
+// ClearExamples clears the value of the "examples" field.
+func (au *AgentUpdate) ClearExamples() *AgentUpdate {
+	au.mutation.ClearExamples()
+	return au
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (au *AgentUpdate) SetOrganizationID(u uint64) *AgentUpdate {
 	au.mutation.ResetOrganizationID()
@@ -316,9 +328,15 @@ func (au *AgentUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if value, ok := au.mutation.Background(); ok {
 		_spec.SetField(agent.FieldBackground, field.TypeString, value)
 	}
+	if au.mutation.BackgroundCleared() {
+		_spec.ClearField(agent.FieldBackground, field.TypeString)
+	}
 	if value, ok := au.mutation.Examples(); ok {
 		_spec.SetField(agent.FieldExamples, field.TypeString, value)
 	}
+	if au.mutation.ExamplesCleared() {
+		_spec.ClearField(agent.FieldExamples, field.TypeString)
+	}
 	if value, ok := au.mutation.OrganizationID(); ok {
 		_spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
 	}
@@ -485,6 +503,12 @@ func (auo *AgentUpdateOne) SetNillableBackground(s *string) *AgentUpdateOne {
 	return auo
 }
 
+// ClearBackground clears the value of the "background" field.
+func (auo *AgentUpdateOne) ClearBackground() *AgentUpdateOne {
+	auo.mutation.ClearBackground()
+	return auo
+}
+
 // SetExamples sets the "examples" field.
 func (auo *AgentUpdateOne) SetExamples(s string) *AgentUpdateOne {
 	auo.mutation.SetExamples(s)
@@ -499,6 +523,12 @@ func (auo *AgentUpdateOne) SetNillableExamples(s *string) *AgentUpdateOne {
 	return auo
 }
 
+// ClearExamples clears the value of the "examples" field.
+func (auo *AgentUpdateOne) ClearExamples() *AgentUpdateOne {
+	auo.mutation.ClearExamples()
+	return auo
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (auo *AgentUpdateOne) SetOrganizationID(u uint64) *AgentUpdateOne {
 	auo.mutation.ResetOrganizationID()
@@ -707,9 +737,15 @@ func (auo *AgentUpdateOne) sqlSave(ctx context.Context) (_node *Agent, err error
 	if value, ok := auo.mutation.Background(); ok {
 		_spec.SetField(agent.FieldBackground, field.TypeString, value)
 	}
+	if auo.mutation.BackgroundCleared() {
+		_spec.ClearField(agent.FieldBackground, field.TypeString)
+	}
 	if value, ok := auo.mutation.Examples(); ok {
 		_spec.SetField(agent.FieldExamples, field.TypeString, value)
 	}
+	if auo.mutation.ExamplesCleared() {
+		_spec.ClearField(agent.FieldExamples, field.TypeString)
+	}
 	if value, ok := auo.mutation.OrganizationID(); ok {
 		_spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
 	}

+ 2 - 2
ent/migrate/schema.go

@@ -18,8 +18,8 @@ var (
 		{Name: "name", Type: field.TypeString, Size: 20, Comment: "name | 角色名称"},
 		{Name: "role", Type: field.TypeString, Size: 1000, Comment: "role | 角色设定"},
 		{Name: "status", Type: field.TypeInt, Nullable: true, Comment: "status | 状态 1-正常 2-禁用", Default: 1},
-		{Name: "background", Type: field.TypeString, Size: 1000, Comment: "background | 背景介绍"},
-		{Name: "examples", Type: field.TypeString, Size: 5000, Comment: "examples | 对话案例"},
+		{Name: "background", Type: field.TypeString, Nullable: true, Size: 1000, Comment: "background | 背景介绍"},
+		{Name: "examples", Type: field.TypeString, Nullable: true, Size: 5000, Comment: "examples | 对话案例"},
 		{Name: "organization_id", Type: field.TypeUint64, Comment: "organization_id | 租户ID"},
 	}
 	// AgentTable holds the schema information for the "agent" table.

+ 38 - 0
ent/mutation.go

@@ -476,9 +476,22 @@ func (m *AgentMutation) OldBackground(ctx context.Context) (v string, err error)
 	return oldValue.Background, nil
 }
 
+// ClearBackground clears the value of the "background" field.
+func (m *AgentMutation) ClearBackground() {
+	m.background = nil
+	m.clearedFields[agent.FieldBackground] = struct{}{}
+}
+
+// BackgroundCleared returns if the "background" field was cleared in this mutation.
+func (m *AgentMutation) BackgroundCleared() bool {
+	_, ok := m.clearedFields[agent.FieldBackground]
+	return ok
+}
+
 // ResetBackground resets all changes to the "background" field.
 func (m *AgentMutation) ResetBackground() {
 	m.background = nil
+	delete(m.clearedFields, agent.FieldBackground)
 }
 
 // SetExamples sets the "examples" field.
@@ -512,9 +525,22 @@ func (m *AgentMutation) OldExamples(ctx context.Context) (v string, err error) {
 	return oldValue.Examples, nil
 }
 
+// ClearExamples clears the value of the "examples" field.
+func (m *AgentMutation) ClearExamples() {
+	m.examples = nil
+	m.clearedFields[agent.FieldExamples] = struct{}{}
+}
+
+// ExamplesCleared returns if the "examples" field was cleared in this mutation.
+func (m *AgentMutation) ExamplesCleared() bool {
+	_, ok := m.clearedFields[agent.FieldExamples]
+	return ok
+}
+
 // ResetExamples resets all changes to the "examples" field.
 func (m *AgentMutation) ResetExamples() {
 	m.examples = nil
+	delete(m.clearedFields, agent.FieldExamples)
 }
 
 // SetOrganizationID sets the "organization_id" field.
@@ -877,6 +903,12 @@ func (m *AgentMutation) ClearedFields() []string {
 	if m.FieldCleared(agent.FieldStatus) {
 		fields = append(fields, agent.FieldStatus)
 	}
+	if m.FieldCleared(agent.FieldBackground) {
+		fields = append(fields, agent.FieldBackground)
+	}
+	if m.FieldCleared(agent.FieldExamples) {
+		fields = append(fields, agent.FieldExamples)
+	}
 	return fields
 }
 
@@ -897,6 +929,12 @@ func (m *AgentMutation) ClearField(name string) error {
 	case agent.FieldStatus:
 		m.ClearStatus()
 		return nil
+	case agent.FieldBackground:
+		m.ClearBackground()
+		return nil
+	case agent.FieldExamples:
+		m.ClearExamples()
+		return nil
 	}
 	return fmt.Errorf("unknown Agent nullable field %s", name)
 }

+ 2 - 2
ent/schema/agent.go

@@ -21,8 +21,8 @@ func (Agent) Fields() []ent.Field {
 		field.String("name").MaxLen(20).Comment("name | 角色名称"),
 		field.String("role").MaxLen(1000).Comment("role | 角色设定"),
 		field.Int("status").Optional().Range(1, 2).Default(1).Comment("status | 状态 1-正常 2-禁用"),
-		field.String("background").MaxLen(1000).Comment("background | 背景介绍"),
-		field.String("examples").MaxLen(5000).Comment("examples | 对话案例"),
+		field.String("background").Optional().MaxLen(1000).Comment("background | 背景介绍"),
+		field.String("examples").Optional().MaxLen(5000).Comment("examples | 对话案例"),
 		field.Uint64("organization_id").Positive().Comment("organization_id | 租户ID"),
 	}
 }