diff --git a/app/controlplane/pkg/data/ent/integrationattachment.go b/app/controlplane/pkg/data/ent/integrationattachment.go index 1c61ed505..7063f419f 100644 --- a/app/controlplane/pkg/data/ent/integrationattachment.go +++ b/app/controlplane/pkg/data/ent/integrationattachment.go @@ -26,11 +26,12 @@ type IntegrationAttachment struct { Configuration []byte `json:"configuration,omitempty"` // DeletedAt holds the value of the "deleted_at" field. DeletedAt time.Time `json:"deleted_at,omitempty"` + // WorkflowID holds the value of the "workflow_id" field. + WorkflowID uuid.UUID `json:"workflow_id,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the IntegrationAttachmentQuery when eager-loading is set. Edges IntegrationAttachmentEdges `json:"edges"` integration_attachment_integration *uuid.UUID - integration_attachment_workflow *uuid.UUID selectValues sql.SelectValues } @@ -76,12 +77,10 @@ func (*IntegrationAttachment) scanValues(columns []string) ([]any, error) { values[i] = new([]byte) case integrationattachment.FieldCreatedAt, integrationattachment.FieldDeletedAt: values[i] = new(sql.NullTime) - case integrationattachment.FieldID: + case integrationattachment.FieldID, integrationattachment.FieldWorkflowID: values[i] = new(uuid.UUID) case integrationattachment.ForeignKeys[0]: // integration_attachment_integration values[i] = &sql.NullScanner{S: new(uuid.UUID)} - case integrationattachment.ForeignKeys[1]: // integration_attachment_workflow - values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: values[i] = new(sql.UnknownType) } @@ -121,6 +120,12 @@ func (ia *IntegrationAttachment) assignValues(columns []string, values []any) er } else if value.Valid { ia.DeletedAt = value.Time } + case integrationattachment.FieldWorkflowID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field workflow_id", values[i]) + } else if value != nil { + ia.WorkflowID = *value + } case integrationattachment.ForeignKeys[0]: if value, ok := values[i].(*sql.NullScanner); !ok { return fmt.Errorf("unexpected type %T for field integration_attachment_integration", values[i]) @@ -128,13 +133,6 @@ func (ia *IntegrationAttachment) assignValues(columns []string, values []any) er ia.integration_attachment_integration = new(uuid.UUID) *ia.integration_attachment_integration = *value.S.(*uuid.UUID) } - case integrationattachment.ForeignKeys[1]: - if value, ok := values[i].(*sql.NullScanner); !ok { - return fmt.Errorf("unexpected type %T for field integration_attachment_workflow", values[i]) - } else if value.Valid { - ia.integration_attachment_workflow = new(uuid.UUID) - *ia.integration_attachment_workflow = *value.S.(*uuid.UUID) - } default: ia.selectValues.Set(columns[i], values[i]) } @@ -189,6 +187,9 @@ func (ia *IntegrationAttachment) String() string { builder.WriteString(", ") builder.WriteString("deleted_at=") builder.WriteString(ia.DeletedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("workflow_id=") + builder.WriteString(fmt.Sprintf("%v", ia.WorkflowID)) builder.WriteByte(')') return builder.String() } diff --git a/app/controlplane/pkg/data/ent/integrationattachment/integrationattachment.go b/app/controlplane/pkg/data/ent/integrationattachment/integrationattachment.go index ce092e1f0..4a4bdf93e 100644 --- a/app/controlplane/pkg/data/ent/integrationattachment/integrationattachment.go +++ b/app/controlplane/pkg/data/ent/integrationattachment/integrationattachment.go @@ -21,6 +21,8 @@ const ( FieldConfiguration = "configuration" // FieldDeletedAt holds the string denoting the deleted_at field in the database. FieldDeletedAt = "deleted_at" + // FieldWorkflowID holds the string denoting the workflow_id field in the database. + FieldWorkflowID = "workflow_id" // EdgeIntegration holds the string denoting the integration edge name in mutations. EdgeIntegration = "integration" // EdgeWorkflow holds the string denoting the workflow edge name in mutations. @@ -40,7 +42,7 @@ const ( // It exists in this package in order to avoid circular dependency with the "workflow" package. WorkflowInverseTable = "workflows" // WorkflowColumn is the table column denoting the workflow relation/edge. - WorkflowColumn = "integration_attachment_workflow" + WorkflowColumn = "workflow_id" ) // Columns holds all SQL columns for integrationattachment fields. @@ -49,13 +51,13 @@ var Columns = []string{ FieldCreatedAt, FieldConfiguration, FieldDeletedAt, + FieldWorkflowID, } // ForeignKeys holds the SQL foreign-keys that are owned by the "integration_attachments" // table and are not defined as standalone fields in the schema. var ForeignKeys = []string{ "integration_attachment_integration", - "integration_attachment_workflow", } // ValidColumn reports if the column name is valid (part of the table columns). @@ -98,6 +100,11 @@ func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() } +// ByWorkflowID orders the results by the workflow_id field. +func ByWorkflowID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldWorkflowID, opts...).ToFunc() +} + // ByIntegrationField orders the results by integration field. func ByIntegrationField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { diff --git a/app/controlplane/pkg/data/ent/integrationattachment/where.go b/app/controlplane/pkg/data/ent/integrationattachment/where.go index 486911e80..b18bab00c 100644 --- a/app/controlplane/pkg/data/ent/integrationattachment/where.go +++ b/app/controlplane/pkg/data/ent/integrationattachment/where.go @@ -71,6 +71,11 @@ func DeletedAt(v time.Time) predicate.IntegrationAttachment { return predicate.IntegrationAttachment(sql.FieldEQ(FieldDeletedAt, v)) } +// WorkflowID applies equality check predicate on the "workflow_id" field. It's identical to WorkflowIDEQ. +func WorkflowID(v uuid.UUID) predicate.IntegrationAttachment { + return predicate.IntegrationAttachment(sql.FieldEQ(FieldWorkflowID, v)) +} + // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.IntegrationAttachment { return predicate.IntegrationAttachment(sql.FieldEQ(FieldCreatedAt, v)) @@ -211,6 +216,26 @@ func DeletedAtNotNil() predicate.IntegrationAttachment { return predicate.IntegrationAttachment(sql.FieldNotNull(FieldDeletedAt)) } +// WorkflowIDEQ applies the EQ predicate on the "workflow_id" field. +func WorkflowIDEQ(v uuid.UUID) predicate.IntegrationAttachment { + return predicate.IntegrationAttachment(sql.FieldEQ(FieldWorkflowID, v)) +} + +// WorkflowIDNEQ applies the NEQ predicate on the "workflow_id" field. +func WorkflowIDNEQ(v uuid.UUID) predicate.IntegrationAttachment { + return predicate.IntegrationAttachment(sql.FieldNEQ(FieldWorkflowID, v)) +} + +// WorkflowIDIn applies the In predicate on the "workflow_id" field. +func WorkflowIDIn(vs ...uuid.UUID) predicate.IntegrationAttachment { + return predicate.IntegrationAttachment(sql.FieldIn(FieldWorkflowID, vs...)) +} + +// WorkflowIDNotIn applies the NotIn predicate on the "workflow_id" field. +func WorkflowIDNotIn(vs ...uuid.UUID) predicate.IntegrationAttachment { + return predicate.IntegrationAttachment(sql.FieldNotIn(FieldWorkflowID, vs...)) +} + // HasIntegration applies the HasEdge predicate on the "integration" edge. func HasIntegration() predicate.IntegrationAttachment { return predicate.IntegrationAttachment(func(s *sql.Selector) { diff --git a/app/controlplane/pkg/data/ent/integrationattachment_create.go b/app/controlplane/pkg/data/ent/integrationattachment_create.go index 752eeeb45..a77b66448 100644 --- a/app/controlplane/pkg/data/ent/integrationattachment_create.go +++ b/app/controlplane/pkg/data/ent/integrationattachment_create.go @@ -57,6 +57,12 @@ func (iac *IntegrationAttachmentCreate) SetNillableDeletedAt(t *time.Time) *Inte return iac } +// SetWorkflowID sets the "workflow_id" field. +func (iac *IntegrationAttachmentCreate) SetWorkflowID(u uuid.UUID) *IntegrationAttachmentCreate { + iac.mutation.SetWorkflowID(u) + return iac +} + // SetID sets the "id" field. func (iac *IntegrationAttachmentCreate) SetID(u uuid.UUID) *IntegrationAttachmentCreate { iac.mutation.SetID(u) @@ -82,12 +88,6 @@ func (iac *IntegrationAttachmentCreate) SetIntegration(i *Integration) *Integrat return iac.SetIntegrationID(i.ID) } -// SetWorkflowID sets the "workflow" edge to the Workflow entity by ID. -func (iac *IntegrationAttachmentCreate) SetWorkflowID(id uuid.UUID) *IntegrationAttachmentCreate { - iac.mutation.SetWorkflowID(id) - return iac -} - // SetWorkflow sets the "workflow" edge to the Workflow entity. func (iac *IntegrationAttachmentCreate) SetWorkflow(w *Workflow) *IntegrationAttachmentCreate { return iac.SetWorkflowID(w.ID) @@ -143,6 +143,9 @@ func (iac *IntegrationAttachmentCreate) check() error { if _, ok := iac.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "IntegrationAttachment.created_at"`)} } + if _, ok := iac.mutation.WorkflowID(); !ok { + return &ValidationError{Name: "workflow_id", err: errors.New(`ent: missing required field "IntegrationAttachment.workflow_id"`)} + } if len(iac.mutation.IntegrationIDs()) == 0 { return &ValidationError{Name: "integration", err: errors.New(`ent: missing required edge "IntegrationAttachment.integration"`)} } @@ -227,7 +230,7 @@ func (iac *IntegrationAttachmentCreate) createSpec() (*IntegrationAttachment, *s for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } - _node.integration_attachment_workflow = &nodes[0] + _node.WorkflowID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } return _node, _spec diff --git a/app/controlplane/pkg/data/ent/integrationattachment_query.go b/app/controlplane/pkg/data/ent/integrationattachment_query.go index 509b6dfb3..78f851785 100644 --- a/app/controlplane/pkg/data/ent/integrationattachment_query.go +++ b/app/controlplane/pkg/data/ent/integrationattachment_query.go @@ -416,7 +416,7 @@ func (iaq *IntegrationAttachmentQuery) sqlAll(ctx context.Context, hooks ...quer iaq.withWorkflow != nil, } ) - if iaq.withIntegration != nil || iaq.withWorkflow != nil { + if iaq.withIntegration != nil { withFKs = true } if withFKs { @@ -494,10 +494,7 @@ func (iaq *IntegrationAttachmentQuery) loadWorkflow(ctx context.Context, query * ids := make([]uuid.UUID, 0, len(nodes)) nodeids := make(map[uuid.UUID][]*IntegrationAttachment) for i := range nodes { - if nodes[i].integration_attachment_workflow == nil { - continue - } - fk := *nodes[i].integration_attachment_workflow + fk := nodes[i].WorkflowID if _, ok := nodeids[fk]; !ok { ids = append(ids, fk) } @@ -514,7 +511,7 @@ func (iaq *IntegrationAttachmentQuery) loadWorkflow(ctx context.Context, query * for _, n := range neighbors { nodes, ok := nodeids[n.ID] if !ok { - return fmt.Errorf(`unexpected foreign-key "integration_attachment_workflow" returned %v`, n.ID) + return fmt.Errorf(`unexpected foreign-key "workflow_id" returned %v`, n.ID) } for i := range nodes { assign(nodes[i], n) @@ -551,6 +548,9 @@ func (iaq *IntegrationAttachmentQuery) querySpec() *sqlgraph.QuerySpec { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } + if iaq.withWorkflow != nil { + _spec.Node.AddColumnOnce(integrationattachment.FieldWorkflowID) + } } if ps := iaq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { diff --git a/app/controlplane/pkg/data/ent/integrationattachment_update.go b/app/controlplane/pkg/data/ent/integrationattachment_update.go index 31ba04340..e83ac0a75 100644 --- a/app/controlplane/pkg/data/ent/integrationattachment_update.go +++ b/app/controlplane/pkg/data/ent/integrationattachment_update.go @@ -64,6 +64,20 @@ func (iau *IntegrationAttachmentUpdate) ClearDeletedAt() *IntegrationAttachmentU return iau } +// SetWorkflowID sets the "workflow_id" field. +func (iau *IntegrationAttachmentUpdate) SetWorkflowID(u uuid.UUID) *IntegrationAttachmentUpdate { + iau.mutation.SetWorkflowID(u) + return iau +} + +// SetNillableWorkflowID sets the "workflow_id" field if the given value is not nil. +func (iau *IntegrationAttachmentUpdate) SetNillableWorkflowID(u *uuid.UUID) *IntegrationAttachmentUpdate { + if u != nil { + iau.SetWorkflowID(*u) + } + return iau +} + // SetIntegrationID sets the "integration" edge to the Integration entity by ID. func (iau *IntegrationAttachmentUpdate) SetIntegrationID(id uuid.UUID) *IntegrationAttachmentUpdate { iau.mutation.SetIntegrationID(id) @@ -75,12 +89,6 @@ func (iau *IntegrationAttachmentUpdate) SetIntegration(i *Integration) *Integrat return iau.SetIntegrationID(i.ID) } -// SetWorkflowID sets the "workflow" edge to the Workflow entity by ID. -func (iau *IntegrationAttachmentUpdate) SetWorkflowID(id uuid.UUID) *IntegrationAttachmentUpdate { - iau.mutation.SetWorkflowID(id) - return iau -} - // SetWorkflow sets the "workflow" edge to the Workflow entity. func (iau *IntegrationAttachmentUpdate) SetWorkflow(w *Workflow) *IntegrationAttachmentUpdate { return iau.SetWorkflowID(w.ID) @@ -283,6 +291,20 @@ func (iauo *IntegrationAttachmentUpdateOne) ClearDeletedAt() *IntegrationAttachm return iauo } +// SetWorkflowID sets the "workflow_id" field. +func (iauo *IntegrationAttachmentUpdateOne) SetWorkflowID(u uuid.UUID) *IntegrationAttachmentUpdateOne { + iauo.mutation.SetWorkflowID(u) + return iauo +} + +// SetNillableWorkflowID sets the "workflow_id" field if the given value is not nil. +func (iauo *IntegrationAttachmentUpdateOne) SetNillableWorkflowID(u *uuid.UUID) *IntegrationAttachmentUpdateOne { + if u != nil { + iauo.SetWorkflowID(*u) + } + return iauo +} + // SetIntegrationID sets the "integration" edge to the Integration entity by ID. func (iauo *IntegrationAttachmentUpdateOne) SetIntegrationID(id uuid.UUID) *IntegrationAttachmentUpdateOne { iauo.mutation.SetIntegrationID(id) @@ -294,12 +316,6 @@ func (iauo *IntegrationAttachmentUpdateOne) SetIntegration(i *Integration) *Inte return iauo.SetIntegrationID(i.ID) } -// SetWorkflowID sets the "workflow" edge to the Workflow entity by ID. -func (iauo *IntegrationAttachmentUpdateOne) SetWorkflowID(id uuid.UUID) *IntegrationAttachmentUpdateOne { - iauo.mutation.SetWorkflowID(id) - return iauo -} - // SetWorkflow sets the "workflow" edge to the Workflow entity. func (iauo *IntegrationAttachmentUpdateOne) SetWorkflow(w *Workflow) *IntegrationAttachmentUpdateOne { return iauo.SetWorkflowID(w.ID) diff --git a/app/controlplane/pkg/data/ent/migrate/migrations/20240819104758.sql b/app/controlplane/pkg/data/ent/migrate/migrations/20240819104758.sql new file mode 100644 index 000000000..b13000ae7 --- /dev/null +++ b/app/controlplane/pkg/data/ent/migrate/migrations/20240819104758.sql @@ -0,0 +1,3 @@ +-- Modify "integration_attachments" table +ALTER TABLE "integration_attachments" RENAME COLUMN "integration_attachment_workflow" TO "workflow_id"; + diff --git a/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum b/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum index da627f56f..50b38ce8d 100644 --- a/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum +++ b/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:+P9V9gqHKq8FjzFaryKCE1qilT/YwxBerz1b8pQIpdY= +h1:owLoJnDpqhfNOWD2GLr1eO6ea1lXnPCSI0p875WQvdQ= 20230706165452_init-schema.sql h1:VvqbNFEQnCvUVyj2iDYVQQxDM0+sSXqocpt/5H64k8M= 20230710111950-cas-backend.sql h1:A8iBuSzZIEbdsv9ipBtscZQuaBp3V5/VMw7eZH6GX+g= 20230712094107-cas-backends-workflow-runs.sql h1:a5rzxpVGyd56nLRSsKrmCFc9sebg65RWzLghKHh5xvI= @@ -37,3 +37,4 @@ h1:+P9V9gqHKq8FjzFaryKCE1qilT/YwxBerz1b8pQIpdY= 20240620214339.sql h1:32nxfoUXtESJp8Du8r9tczQYNKNccUUm3Qp6tu/ixXE= 20240812125201.sql h1:y7ldOFQz9GiJ9XehYg3La/YzXbD/AUjxBU0WlPAaees= 20240814131848.sql h1:4kyGnh/8rqClszO54yBsk2y2L2EjitYPyX+1OIxF3YA= +20240819104758.sql h1:gJdowymiKto0APLmnMx+3M3oXJBgV2dyqm7Bf3f+RPY= diff --git a/app/controlplane/pkg/data/ent/migrate/schema.go b/app/controlplane/pkg/data/ent/migrate/schema.go index 67d5e87cd..c138267be 100644 --- a/app/controlplane/pkg/data/ent/migrate/schema.go +++ b/app/controlplane/pkg/data/ent/migrate/schema.go @@ -169,7 +169,7 @@ var ( {Name: "configuration", Type: field.TypeBytes, Nullable: true}, {Name: "deleted_at", Type: field.TypeTime, Nullable: true}, {Name: "integration_attachment_integration", Type: field.TypeUUID}, - {Name: "integration_attachment_workflow", Type: field.TypeUUID}, + {Name: "workflow_id", Type: field.TypeUUID}, } // IntegrationAttachmentsTable holds the schema information for the "integration_attachments" table. IntegrationAttachmentsTable = &schema.Table{ diff --git a/app/controlplane/pkg/data/ent/mutation.go b/app/controlplane/pkg/data/ent/mutation.go index e916f84e6..e1163121c 100644 --- a/app/controlplane/pkg/data/ent/mutation.go +++ b/app/controlplane/pkg/data/ent/mutation.go @@ -3626,6 +3626,42 @@ func (m *IntegrationAttachmentMutation) ResetDeletedAt() { delete(m.clearedFields, integrationattachment.FieldDeletedAt) } +// SetWorkflowID sets the "workflow_id" field. +func (m *IntegrationAttachmentMutation) SetWorkflowID(u uuid.UUID) { + m.workflow = &u +} + +// WorkflowID returns the value of the "workflow_id" field in the mutation. +func (m *IntegrationAttachmentMutation) WorkflowID() (r uuid.UUID, exists bool) { + v := m.workflow + if v == nil { + return + } + return *v, true +} + +// OldWorkflowID returns the old "workflow_id" field's value of the IntegrationAttachment entity. +// If the IntegrationAttachment object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *IntegrationAttachmentMutation) OldWorkflowID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldWorkflowID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldWorkflowID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldWorkflowID: %w", err) + } + return oldValue.WorkflowID, nil +} + +// ResetWorkflowID resets all changes to the "workflow_id" field. +func (m *IntegrationAttachmentMutation) ResetWorkflowID() { + m.workflow = nil +} + // SetIntegrationID sets the "integration" edge to the Integration entity by id. func (m *IntegrationAttachmentMutation) SetIntegrationID(id uuid.UUID) { m.integration = &id @@ -3665,14 +3701,10 @@ func (m *IntegrationAttachmentMutation) ResetIntegration() { m.clearedintegration = false } -// SetWorkflowID sets the "workflow" edge to the Workflow entity by id. -func (m *IntegrationAttachmentMutation) SetWorkflowID(id uuid.UUID) { - m.workflow = &id -} - // ClearWorkflow clears the "workflow" edge to the Workflow entity. func (m *IntegrationAttachmentMutation) ClearWorkflow() { m.clearedworkflow = true + m.clearedFields[integrationattachment.FieldWorkflowID] = struct{}{} } // WorkflowCleared reports if the "workflow" edge to the Workflow entity was cleared. @@ -3680,14 +3712,6 @@ func (m *IntegrationAttachmentMutation) WorkflowCleared() bool { return m.clearedworkflow } -// WorkflowID returns the "workflow" edge ID in the mutation. -func (m *IntegrationAttachmentMutation) WorkflowID() (id uuid.UUID, exists bool) { - if m.workflow != nil { - return *m.workflow, true - } - return -} - // WorkflowIDs returns the "workflow" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // WorkflowID instead. It exists only for internal usage by the builders. @@ -3738,7 +3762,7 @@ func (m *IntegrationAttachmentMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *IntegrationAttachmentMutation) Fields() []string { - fields := make([]string, 0, 3) + fields := make([]string, 0, 4) if m.created_at != nil { fields = append(fields, integrationattachment.FieldCreatedAt) } @@ -3748,6 +3772,9 @@ func (m *IntegrationAttachmentMutation) Fields() []string { if m.deleted_at != nil { fields = append(fields, integrationattachment.FieldDeletedAt) } + if m.workflow != nil { + fields = append(fields, integrationattachment.FieldWorkflowID) + } return fields } @@ -3762,6 +3789,8 @@ func (m *IntegrationAttachmentMutation) Field(name string) (ent.Value, bool) { return m.Configuration() case integrationattachment.FieldDeletedAt: return m.DeletedAt() + case integrationattachment.FieldWorkflowID: + return m.WorkflowID() } return nil, false } @@ -3777,6 +3806,8 @@ func (m *IntegrationAttachmentMutation) OldField(ctx context.Context, name strin return m.OldConfiguration(ctx) case integrationattachment.FieldDeletedAt: return m.OldDeletedAt(ctx) + case integrationattachment.FieldWorkflowID: + return m.OldWorkflowID(ctx) } return nil, fmt.Errorf("unknown IntegrationAttachment field %s", name) } @@ -3807,6 +3838,13 @@ func (m *IntegrationAttachmentMutation) SetField(name string, value ent.Value) e } m.SetDeletedAt(v) return nil + case integrationattachment.FieldWorkflowID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetWorkflowID(v) + return nil } return fmt.Errorf("unknown IntegrationAttachment field %s", name) } @@ -3880,6 +3918,9 @@ func (m *IntegrationAttachmentMutation) ResetField(name string) error { case integrationattachment.FieldDeletedAt: m.ResetDeletedAt() return nil + case integrationattachment.FieldWorkflowID: + m.ResetWorkflowID() + return nil } return fmt.Errorf("unknown IntegrationAttachment field %s", name) } diff --git a/app/controlplane/pkg/data/ent/schema-viz.html b/app/controlplane/pkg/data/ent/schema-viz.html index 204f521bd..17308cdbb 100644 --- a/app/controlplane/pkg/data/ent/schema-viz.html +++ b/app/controlplane/pkg/data/ent/schema-viz.html @@ -70,7 +70,7 @@ } - const entGraph = JSON.parse("{\"nodes\":[{\"id\":\"APIToken\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"description\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"expires_at\",\"type\":\"time.Time\"},{\"name\":\"revoked_at\",\"type\":\"time.Time\"},{\"name\":\"organization_id\",\"type\":\"uuid.UUID\"}]},{\"id\":\"CASBackend\",\"fields\":[{\"name\":\"location\",\"type\":\"string\"},{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"provider\",\"type\":\"biz.CASBackendProvider\"},{\"name\":\"description\",\"type\":\"string\"},{\"name\":\"secret_name\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"validation_status\",\"type\":\"biz.CASBackendValidationStatus\"},{\"name\":\"validated_at\",\"type\":\"time.Time\"},{\"name\":\"default\",\"type\":\"bool\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"},{\"name\":\"fallback\",\"type\":\"bool\"},{\"name\":\"max_blob_size_bytes\",\"type\":\"int64\"}]},{\"id\":\"CASMapping\",\"fields\":[{\"name\":\"digest\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"}]},{\"id\":\"Integration\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"kind\",\"type\":\"string\"},{\"name\":\"description\",\"type\":\"string\"},{\"name\":\"secret_name\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"configuration\",\"type\":\"[]byte\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"}]},{\"id\":\"IntegrationAttachment\",\"fields\":[{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"configuration\",\"type\":\"[]byte\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"}]},{\"id\":\"Membership\",\"fields\":[{\"name\":\"current\",\"type\":\"bool\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"updated_at\",\"type\":\"time.Time\"},{\"name\":\"role\",\"type\":\"authz.Role\"}]},{\"id\":\"OrgInvitation\",\"fields\":[{\"name\":\"receiver_email\",\"type\":\"string\"},{\"name\":\"status\",\"type\":\"biz.OrgInvitationStatus\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"},{\"name\":\"organization_id\",\"type\":\"uuid.UUID\"},{\"name\":\"sender_id\",\"type\":\"uuid.UUID\"},{\"name\":\"role\",\"type\":\"authz.Role\"}]},{\"id\":\"Organization\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"}]},{\"id\":\"Referrer\",\"fields\":[{\"name\":\"digest\",\"type\":\"string\"},{\"name\":\"kind\",\"type\":\"string\"},{\"name\":\"downloadable\",\"type\":\"bool\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"metadata\",\"type\":\"map[string]string\"},{\"name\":\"annotations\",\"type\":\"map[string]string\"}]},{\"id\":\"RobotAccount\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"revoked_at\",\"type\":\"time.Time\"}]},{\"id\":\"User\",\"fields\":[{\"name\":\"email\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"}]},{\"id\":\"Workflow\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"project\",\"type\":\"string\"},{\"name\":\"team\",\"type\":\"string\"},{\"name\":\"runs_count\",\"type\":\"int\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"},{\"name\":\"public\",\"type\":\"bool\"},{\"name\":\"organization_id\",\"type\":\"uuid.UUID\"},{\"name\":\"description\",\"type\":\"string\"}]},{\"id\":\"WorkflowContract\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"},{\"name\":\"description\",\"type\":\"string\"}]},{\"id\":\"WorkflowContractVersion\",\"fields\":[{\"name\":\"body\",\"type\":\"[]byte\"},{\"name\":\"revision\",\"type\":\"int\"},{\"name\":\"created_at\",\"type\":\"time.Time\"}]},{\"id\":\"WorkflowRun\",\"fields\":[{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"finished_at\",\"type\":\"time.Time\"},{\"name\":\"state\",\"type\":\"biz.WorkflowRunStatus\"},{\"name\":\"reason\",\"type\":\"string\"},{\"name\":\"run_url\",\"type\":\"string\"},{\"name\":\"runner_type\",\"type\":\"string\"},{\"name\":\"attestation\",\"type\":\"*dsse.Envelope\"},{\"name\":\"attestation_digest\",\"type\":\"string\"},{\"name\":\"attestation_state\",\"type\":\"[]byte\"},{\"name\":\"contract_revision_used\",\"type\":\"int\"},{\"name\":\"contract_revision_latest\",\"type\":\"int\"}]}],\"edges\":[{\"from\":\"CASMapping\",\"to\":\"CASBackend\",\"label\":\"cas_backend\"},{\"from\":\"CASMapping\",\"to\":\"WorkflowRun\",\"label\":\"workflow_run\"},{\"from\":\"CASMapping\",\"to\":\"Organization\",\"label\":\"organization\"},{\"from\":\"IntegrationAttachment\",\"to\":\"Integration\",\"label\":\"integration\"},{\"from\":\"IntegrationAttachment\",\"to\":\"Workflow\",\"label\":\"workflow\"},{\"from\":\"OrgInvitation\",\"to\":\"Organization\",\"label\":\"organization\"},{\"from\":\"OrgInvitation\",\"to\":\"User\",\"label\":\"sender\"},{\"from\":\"Organization\",\"to\":\"Membership\",\"label\":\"memberships\"},{\"from\":\"Organization\",\"to\":\"WorkflowContract\",\"label\":\"workflow_contracts\"},{\"from\":\"Organization\",\"to\":\"Workflow\",\"label\":\"workflows\"},{\"from\":\"Organization\",\"to\":\"CASBackend\",\"label\":\"cas_backends\"},{\"from\":\"Organization\",\"to\":\"Integration\",\"label\":\"integrations\"},{\"from\":\"Organization\",\"to\":\"APIToken\",\"label\":\"api_tokens\"},{\"from\":\"Referrer\",\"to\":\"Referrer\",\"label\":\"references\"},{\"from\":\"Referrer\",\"to\":\"Workflow\",\"label\":\"workflows\"},{\"from\":\"User\",\"to\":\"Membership\",\"label\":\"memberships\"},{\"from\":\"Workflow\",\"to\":\"RobotAccount\",\"label\":\"robotaccounts\"},{\"from\":\"Workflow\",\"to\":\"WorkflowRun\",\"label\":\"workflowruns\"},{\"from\":\"Workflow\",\"to\":\"WorkflowContract\",\"label\":\"contract\"},{\"from\":\"WorkflowContract\",\"to\":\"WorkflowContractVersion\",\"label\":\"versions\"},{\"from\":\"WorkflowRun\",\"to\":\"WorkflowContractVersion\",\"label\":\"contract_version\"},{\"from\":\"WorkflowRun\",\"to\":\"CASBackend\",\"label\":\"cas_backends\"}]}"); + const entGraph = JSON.parse("{\"nodes\":[{\"id\":\"APIToken\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"description\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"expires_at\",\"type\":\"time.Time\"},{\"name\":\"revoked_at\",\"type\":\"time.Time\"},{\"name\":\"organization_id\",\"type\":\"uuid.UUID\"}]},{\"id\":\"CASBackend\",\"fields\":[{\"name\":\"location\",\"type\":\"string\"},{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"provider\",\"type\":\"biz.CASBackendProvider\"},{\"name\":\"description\",\"type\":\"string\"},{\"name\":\"secret_name\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"validation_status\",\"type\":\"biz.CASBackendValidationStatus\"},{\"name\":\"validated_at\",\"type\":\"time.Time\"},{\"name\":\"default\",\"type\":\"bool\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"},{\"name\":\"fallback\",\"type\":\"bool\"},{\"name\":\"max_blob_size_bytes\",\"type\":\"int64\"}]},{\"id\":\"CASMapping\",\"fields\":[{\"name\":\"digest\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"}]},{\"id\":\"Integration\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"kind\",\"type\":\"string\"},{\"name\":\"description\",\"type\":\"string\"},{\"name\":\"secret_name\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"configuration\",\"type\":\"[]byte\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"}]},{\"id\":\"IntegrationAttachment\",\"fields\":[{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"configuration\",\"type\":\"[]byte\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"},{\"name\":\"workflow_id\",\"type\":\"uuid.UUID\"}]},{\"id\":\"Membership\",\"fields\":[{\"name\":\"current\",\"type\":\"bool\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"updated_at\",\"type\":\"time.Time\"},{\"name\":\"role\",\"type\":\"authz.Role\"}]},{\"id\":\"OrgInvitation\",\"fields\":[{\"name\":\"receiver_email\",\"type\":\"string\"},{\"name\":\"status\",\"type\":\"biz.OrgInvitationStatus\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"},{\"name\":\"organization_id\",\"type\":\"uuid.UUID\"},{\"name\":\"sender_id\",\"type\":\"uuid.UUID\"},{\"name\":\"role\",\"type\":\"authz.Role\"}]},{\"id\":\"Organization\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"}]},{\"id\":\"Referrer\",\"fields\":[{\"name\":\"digest\",\"type\":\"string\"},{\"name\":\"kind\",\"type\":\"string\"},{\"name\":\"downloadable\",\"type\":\"bool\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"metadata\",\"type\":\"map[string]string\"},{\"name\":\"annotations\",\"type\":\"map[string]string\"}]},{\"id\":\"RobotAccount\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"revoked_at\",\"type\":\"time.Time\"}]},{\"id\":\"User\",\"fields\":[{\"name\":\"email\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"}]},{\"id\":\"Workflow\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"project\",\"type\":\"string\"},{\"name\":\"team\",\"type\":\"string\"},{\"name\":\"runs_count\",\"type\":\"int\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"},{\"name\":\"public\",\"type\":\"bool\"},{\"name\":\"organization_id\",\"type\":\"uuid.UUID\"},{\"name\":\"description\",\"type\":\"string\"}]},{\"id\":\"WorkflowContract\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"deleted_at\",\"type\":\"time.Time\"},{\"name\":\"description\",\"type\":\"string\"}]},{\"id\":\"WorkflowContractVersion\",\"fields\":[{\"name\":\"body\",\"type\":\"[]byte\"},{\"name\":\"revision\",\"type\":\"int\"},{\"name\":\"created_at\",\"type\":\"time.Time\"}]},{\"id\":\"WorkflowRun\",\"fields\":[{\"name\":\"created_at\",\"type\":\"time.Time\"},{\"name\":\"finished_at\",\"type\":\"time.Time\"},{\"name\":\"state\",\"type\":\"biz.WorkflowRunStatus\"},{\"name\":\"reason\",\"type\":\"string\"},{\"name\":\"run_url\",\"type\":\"string\"},{\"name\":\"runner_type\",\"type\":\"string\"},{\"name\":\"attestation\",\"type\":\"*dsse.Envelope\"},{\"name\":\"attestation_digest\",\"type\":\"string\"},{\"name\":\"attestation_state\",\"type\":\"[]byte\"},{\"name\":\"contract_revision_used\",\"type\":\"int\"},{\"name\":\"contract_revision_latest\",\"type\":\"int\"}]}],\"edges\":[{\"from\":\"CASMapping\",\"to\":\"CASBackend\",\"label\":\"cas_backend\"},{\"from\":\"CASMapping\",\"to\":\"WorkflowRun\",\"label\":\"workflow_run\"},{\"from\":\"CASMapping\",\"to\":\"Organization\",\"label\":\"organization\"},{\"from\":\"IntegrationAttachment\",\"to\":\"Integration\",\"label\":\"integration\"},{\"from\":\"IntegrationAttachment\",\"to\":\"Workflow\",\"label\":\"workflow\"},{\"from\":\"OrgInvitation\",\"to\":\"Organization\",\"label\":\"organization\"},{\"from\":\"OrgInvitation\",\"to\":\"User\",\"label\":\"sender\"},{\"from\":\"Organization\",\"to\":\"Membership\",\"label\":\"memberships\"},{\"from\":\"Organization\",\"to\":\"WorkflowContract\",\"label\":\"workflow_contracts\"},{\"from\":\"Organization\",\"to\":\"Workflow\",\"label\":\"workflows\"},{\"from\":\"Organization\",\"to\":\"CASBackend\",\"label\":\"cas_backends\"},{\"from\":\"Organization\",\"to\":\"Integration\",\"label\":\"integrations\"},{\"from\":\"Organization\",\"to\":\"APIToken\",\"label\":\"api_tokens\"},{\"from\":\"Referrer\",\"to\":\"Referrer\",\"label\":\"references\"},{\"from\":\"Referrer\",\"to\":\"Workflow\",\"label\":\"workflows\"},{\"from\":\"User\",\"to\":\"Membership\",\"label\":\"memberships\"},{\"from\":\"Workflow\",\"to\":\"RobotAccount\",\"label\":\"robotaccounts\"},{\"from\":\"Workflow\",\"to\":\"WorkflowRun\",\"label\":\"workflowruns\"},{\"from\":\"Workflow\",\"to\":\"WorkflowContract\",\"label\":\"contract\"},{\"from\":\"WorkflowContract\",\"to\":\"WorkflowContractVersion\",\"label\":\"versions\"},{\"from\":\"WorkflowRun\",\"to\":\"WorkflowContractVersion\",\"label\":\"contract_version\"},{\"from\":\"WorkflowRun\",\"to\":\"CASBackend\",\"label\":\"cas_backends\"}]}"); const nodes = new vis.DataSet((entGraph.nodes || []).map(n => ({ id: n.id, diff --git a/app/controlplane/pkg/data/ent/schema/integrationattachment.go b/app/controlplane/pkg/data/ent/schema/integrationattachment.go index 3233c4c9a..bd5de2a37 100644 --- a/app/controlplane/pkg/data/ent/schema/integrationattachment.go +++ b/app/controlplane/pkg/data/ent/schema/integrationattachment.go @@ -38,12 +38,13 @@ func (IntegrationAttachment) Fields() []ent.Field { Annotations(&entsql.Annotation{Default: "CURRENT_TIMESTAMP"}), field.Bytes("configuration").Optional(), field.Time("deleted_at").Optional(), + field.UUID("workflow_id", uuid.UUID{}), } } func (IntegrationAttachment) Edges() []ent.Edge { return []ent.Edge{ edge.To("integration", Integration.Type).Unique().Required().Annotations(entsql.Annotation{OnDelete: entsql.Cascade}), - edge.To("workflow", Workflow.Type).Unique().Required().Annotations(entsql.Annotation{OnDelete: entsql.Cascade}), + edge.To("workflow", Workflow.Type).Field("workflow_id").Unique().Required().Annotations(entsql.Annotation{OnDelete: entsql.Cascade}), } } diff --git a/app/controlplane/pkg/data/ent/workflow/workflow.go b/app/controlplane/pkg/data/ent/workflow/workflow.go index 38089a40c..8040df3a8 100644 --- a/app/controlplane/pkg/data/ent/workflow/workflow.go +++ b/app/controlplane/pkg/data/ent/workflow/workflow.go @@ -81,7 +81,7 @@ const ( // It exists in this package in order to avoid circular dependency with the "integrationattachment" package. IntegrationAttachmentsInverseTable = "integration_attachments" // IntegrationAttachmentsColumn is the table column denoting the integration_attachments relation/edge. - IntegrationAttachmentsColumn = "integration_attachment_workflow" + IntegrationAttachmentsColumn = "workflow_id" // ReferrersTable is the table that holds the referrers relation/edge. The primary key declared below. ReferrersTable = "referrer_workflows" // ReferrersInverseTable is the table name for the Referrer entity. diff --git a/app/controlplane/pkg/data/ent/workflow_query.go b/app/controlplane/pkg/data/ent/workflow_query.go index 955014a33..16b521351 100644 --- a/app/controlplane/pkg/data/ent/workflow_query.go +++ b/app/controlplane/pkg/data/ent/workflow_query.go @@ -771,6 +771,9 @@ func (wq *WorkflowQuery) loadIntegrationAttachments(ctx context.Context, query * } } query.withFKs = true + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(integrationattachment.FieldWorkflowID) + } query.Where(predicate.IntegrationAttachment(func(s *sql.Selector) { s.Where(sql.InValues(s.C(workflow.IntegrationAttachmentsColumn), fks...)) })) @@ -779,13 +782,10 @@ func (wq *WorkflowQuery) loadIntegrationAttachments(ctx context.Context, query * return err } for _, n := range neighbors { - fk := n.integration_attachment_workflow - if fk == nil { - return fmt.Errorf(`foreign-key "integration_attachment_workflow" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] + fk := n.WorkflowID + node, ok := nodeids[fk] if !ok { - return fmt.Errorf(`unexpected referenced foreign-key "integration_attachment_workflow" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "workflow_id" returned %v for node %v`, fk, n.ID) } assign(node, n) }