Skip to content

Commit 055c36c

Browse files
authored
chore(controlplane): remove robor-account relatioship from workflowrun (#765)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 6a4d91a commit 055c36c

26 files changed

+71
-917
lines changed

app/controlplane/internal/biz/casmapping_integration_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,22 +359,18 @@ func (s *casMappingIntegrationSuite) SetupTest() {
359359
publicWorkflow, err := s.Workflow.Create(ctx, &biz.WorkflowCreateOpts{Name: "test-workflow-public", OrgID: s.org1.ID, Public: true})
360360
assert.NoError(err)
361361

362-
// Robot account
363-
robotAccount, err := s.RobotAccount.Create(ctx, "name", s.org1.ID, workflow.ID.String())
364-
assert.NoError(err)
365-
366362
// Find contract revision
367363
contractVersion, err := s.WorkflowContract.Describe(ctx, s.org1.ID, workflow.ContractID.String(), 0)
368364
assert.NoError(err)
369365

370366
s.workflowRun, err = s.WorkflowRun.Create(ctx, &biz.WorkflowRunCreateOpts{
371-
WorkflowID: workflow.ID.String(), RobotaccountID: robotAccount.ID.String(), ContractRevision: contractVersion, CASBackendID: s.casBackend1.ID,
367+
WorkflowID: workflow.ID.String(), ContractRevision: contractVersion, CASBackendID: s.casBackend1.ID,
372368
RunnerType: "runnerType", RunnerRunURL: "runURL",
373369
})
374370
assert.NoError(err)
375371

376372
s.publicWorkflowRun, err = s.WorkflowRun.Create(ctx, &biz.WorkflowRunCreateOpts{
377-
WorkflowID: publicWorkflow.ID.String(), RobotaccountID: robotAccount.ID.String(), ContractRevision: contractVersion, CASBackendID: s.casBackend1.ID,
373+
WorkflowID: publicWorkflow.ID.String(), ContractRevision: contractVersion, CASBackendID: s.casBackend1.ID,
378374
RunnerType: "runnerType", RunnerRunURL: "runURL",
379375
})
380376
assert.NoError(err)

app/controlplane/internal/biz/referrer_integration_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,6 @@ func (s *referrerIntegrationTestSuite) SetupTest() {
428428
}, nil)
429429
require.NoError(s.T(), err)
430430

431-
// Robot account
432-
robotAccount, err := s.RobotAccount.Create(ctx, "name", s.org1.ID, s.workflow1.ID.String())
433-
require.NoError(s.T(), err)
434-
435431
// Find contract revision
436432
contractVersion, err := s.WorkflowContract.Describe(ctx, s.org1.ID, s.workflow1.ContractID.String(), 0)
437433
require.NoError(s.T(), err)
@@ -441,7 +437,7 @@ func (s *referrerIntegrationTestSuite) SetupTest() {
441437

442438
s.run, err = s.WorkflowRun.Create(ctx,
443439
&biz.WorkflowRunCreateOpts{
444-
WorkflowID: s.workflow1.ID.String(), RobotaccountID: robotAccount.ID.String(), ContractRevision: contractVersion, CASBackendID: casBackend.ID,
440+
WorkflowID: s.workflow1.ID.String(), ContractRevision: contractVersion, CASBackendID: casBackend.ID,
445441
})
446442

447443
require.NoError(s.T(), err)

app/controlplane/internal/biz/workflowrun.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,18 @@ func (uc *WorkflowRunExpirerUseCase) ExpirationSweep(ctx context.Context, olderT
160160
}
161161

162162
type WorkflowRunCreateOpts struct {
163-
WorkflowID, RobotaccountID string
164-
ContractRevision *WorkflowContractWithVersion
165-
RunnerRunURL string
166-
RunnerType string
167-
CASBackendID uuid.UUID
163+
WorkflowID string
164+
ContractRevision *WorkflowContractWithVersion
165+
RunnerRunURL string
166+
RunnerType string
167+
CASBackendID uuid.UUID
168168
}
169169

170170
type WorkflowRunRepoCreateOpts struct {
171-
WorkflowID, RobotaccountID, SchemaVersionID uuid.UUID
172-
RunURL, RunnerType string
173-
Backends []uuid.UUID
174-
LatestRevision, UsedRevision int
171+
WorkflowID, SchemaVersionID uuid.UUID
172+
RunURL, RunnerType string
173+
Backends []uuid.UUID
174+
LatestRevision, UsedRevision int
175175
}
176176

177177
// Create will add a new WorkflowRun, associate it to a schemaVersion and increment the counter in the associated workflow
@@ -181,11 +181,6 @@ func (uc *WorkflowRunUseCase) Create(ctx context.Context, opts *WorkflowRunCreat
181181
return nil, err
182182
}
183183

184-
robotaccountUUID, err := uuid.Parse(opts.RobotaccountID)
185-
if err != nil {
186-
return nil, err
187-
}
188-
189184
if opts.CASBackendID == uuid.Nil {
190185
return nil, errors.New("CASBackendID cannot be nil")
191186
}
@@ -201,7 +196,6 @@ func (uc *WorkflowRunUseCase) Create(ctx context.Context, opts *WorkflowRunCreat
201196
run, err := uc.wfRunRepo.Create(ctx,
202197
&WorkflowRunRepoCreateOpts{
203198
WorkflowID: workflowUUID,
204-
RobotaccountID: robotaccountUUID,
205199
SchemaVersionID: contractRevision.Version.ID,
206200
RunURL: opts.RunnerRunURL,
207201
RunnerType: opts.RunnerType,

app/controlplane/internal/biz/workflowrun_integration_test.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (s *workflowRunIntegrationTestSuite) TestList() {
4141
// Create a finished run
4242
finishedRun, err := s.WorkflowRun.Create(context.Background(),
4343
&biz.WorkflowRunCreateOpts{
44-
WorkflowID: s.workflowOrg2.ID.String(), RobotaccountID: s.robotAccount.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
44+
WorkflowID: s.workflowOrg2.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
4545
})
4646
s.NoError(err)
4747
err = s.WorkflowRun.MarkAsFinished(context.Background(), finishedRun.ID.String(), biz.WorkflowRunSuccess, "")
@@ -119,7 +119,7 @@ func (s *workflowRunIntegrationTestSuite) TestSaveAttestation() {
119119

120120
s.T().Run("valid workflowRun", func(t *testing.T) {
121121
run, err := s.WorkflowRun.Create(ctx, &biz.WorkflowRunCreateOpts{
122-
WorkflowID: s.workflowOrg1.ID.String(), RobotaccountID: s.robotAccount.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
122+
WorkflowID: s.workflowOrg1.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
123123
})
124124
assert.NoError(err)
125125

@@ -241,7 +241,7 @@ func (s *workflowRunIntegrationTestSuite) TestCreate() {
241241

242242
s.T().Run("valid workflowRun", func(t *testing.T) {
243243
run, err := s.WorkflowRun.Create(ctx, &biz.WorkflowRunCreateOpts{
244-
WorkflowID: s.workflowOrg1.ID.String(), RobotaccountID: s.robotAccount.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
244+
WorkflowID: s.workflowOrg1.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
245245
RunnerType: "runnerType", RunnerRunURL: "runURL",
246246
})
247247
assert.NoError(err)
@@ -263,7 +263,7 @@ func (s *workflowRunIntegrationTestSuite) TestContractInformation() {
263263
ctx := context.Background()
264264
s.Run("if it's the first revision of the contract it matches", func() {
265265
run, err := s.WorkflowRun.Create(ctx, &biz.WorkflowRunCreateOpts{
266-
WorkflowID: s.workflowOrg1.ID.String(), RobotaccountID: s.robotAccount.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
266+
WorkflowID: s.workflowOrg1.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
267267
RunnerType: "runnerType", RunnerRunURL: "runURL",
268268
})
269269
s.NoError(err)
@@ -281,7 +281,7 @@ func (s *workflowRunIntegrationTestSuite) TestContractInformation() {
281281
updatedContractRevision.Version = s.contractVersion.Version
282282

283283
run, err := s.WorkflowRun.Create(ctx, &biz.WorkflowRunCreateOpts{
284-
WorkflowID: s.workflowOrg1.ID.String(), RobotaccountID: s.robotAccount.ID.String(), ContractRevision: updatedContractRevision, CASBackendID: s.casBackend.ID,
284+
WorkflowID: s.workflowOrg1.ID.String(), ContractRevision: updatedContractRevision, CASBackendID: s.casBackend.ID,
285285
RunnerType: "runnerType", RunnerRunURL: "runURL",
286286
})
287287
s.NoError(err)
@@ -307,7 +307,6 @@ type workflowRunTestData struct {
307307
casBackend *biz.CASBackend
308308
workflowOrg1, workflowOrg2, workflowPublicOrg2 *biz.Workflow
309309
runOrg1, runOrg2, runOrg2Public *biz.WorkflowRun
310-
robotAccount *biz.RobotAccount
311310
contractVersion *biz.WorkflowContractWithVersion
312311
digestAtt1, digestAttOrg2, digestAttPublic string
313312
}
@@ -340,10 +339,6 @@ func setupWorkflowRunTestData(t *testing.T, suite *testhelpers.TestingUseCases,
340339
s.workflowPublicOrg2, err = suite.Workflow.Create(ctx, &biz.WorkflowCreateOpts{Name: "test-public-workflow", OrgID: s.org2.ID, Public: true})
341340
assert.NoError(err)
342341

343-
// Robot account
344-
s.robotAccount, err = suite.RobotAccount.Create(ctx, "name", s.org.ID, s.workflowOrg1.ID.String())
345-
assert.NoError(err)
346-
347342
// Find contract revision
348343
s.contractVersion, err = suite.WorkflowContract.Describe(ctx, s.org.ID, s.workflowOrg1.ContractID.String(), 0)
349344
assert.NoError(err)
@@ -354,7 +349,7 @@ func setupWorkflowRunTestData(t *testing.T, suite *testhelpers.TestingUseCases,
354349
// Let's create 3 runs, one in org1 and 2 in org2 (one public)
355350
s.runOrg1, err = suite.WorkflowRun.Create(ctx,
356351
&biz.WorkflowRunCreateOpts{
357-
WorkflowID: s.workflowOrg1.ID.String(), RobotaccountID: s.robotAccount.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
352+
WorkflowID: s.workflowOrg1.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
358353
})
359354
assert.NoError(err)
360355
s.digestAtt1, err = suite.WorkflowRun.SaveAttestation(ctx, s.runOrg1.ID.String(), testEnvelope(t, "testdata/attestations/full.json"))
@@ -363,15 +358,15 @@ func setupWorkflowRunTestData(t *testing.T, suite *testhelpers.TestingUseCases,
363358

364359
s.runOrg2, err = suite.WorkflowRun.Create(ctx,
365360
&biz.WorkflowRunCreateOpts{
366-
WorkflowID: s.workflowOrg2.ID.String(), RobotaccountID: s.robotAccount.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
361+
WorkflowID: s.workflowOrg2.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
367362
})
368363
assert.NoError(err)
369364
s.digestAttOrg2, err = suite.WorkflowRun.SaveAttestation(ctx, s.runOrg2.ID.String(), testEnvelope(t, "testdata/attestations/empty.json"))
370365
assert.NoError(err)
371366

372367
s.runOrg2Public, err = suite.WorkflowRun.Create(ctx,
373368
&biz.WorkflowRunCreateOpts{
374-
WorkflowID: s.workflowPublicOrg2.ID.String(), RobotaccountID: s.robotAccount.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
369+
WorkflowID: s.workflowPublicOrg2.ID.String(), ContractRevision: s.contractVersion, CASBackendID: s.casBackend.ID,
375370
})
376371
assert.NoError(err)
377372
s.digestAttPublic, err = suite.WorkflowRun.SaveAttestation(ctx, s.runOrg2Public.ID.String(), testEnvelope(t, "testdata/attestations/with-string.json"))

app/controlplane/internal/data/ent/client.go

Lines changed: 0 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Modify "workflow_runs" table
2+
ALTER TABLE "workflow_runs" DROP COLUMN "robot_account_workflowruns";

app/controlplane/internal/data/ent/migrate/migrations/atlas.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:GyVT999mzRrKOlWt12H4XxliHnPnd8CcTNP18a3HhyE=
1+
h1:MTcZpxDGZjz8SbHEHGfOf/NfCwp4lXiy5SsqQb5JfMk=
22
20230706165452_init-schema.sql h1:VvqbNFEQnCvUVyj2iDYVQQxDM0+sSXqocpt/5H64k8M=
33
20230710111950-cas-backend.sql h1:A8iBuSzZIEbdsv9ipBtscZQuaBp3V5/VMw7eZH6GX+g=
44
20230712094107-cas-backends-workflow-runs.sql h1:a5rzxpVGyd56nLRSsKrmCFc9sebg65RWzLghKHh5xvI=
@@ -32,3 +32,4 @@ h1:GyVT999mzRrKOlWt12H4XxliHnPnd8CcTNP18a3HhyE=
3232
20240401133702.sql h1:eii4LfkjAwGLPKDJjko2tyeynrHNSYG3mfJ9aYs27kM=
3333
20240409133222.sql h1:cvsqMNhFy+AcRla6zUKUX0Z0B816Cg0xPPiTmqiFS3c=
3434
20240410132210.sql h1:Ed1XXWkREYgOeTAAkVv+j3IV215TxgdXq+U5zIZOWuk=
35+
20240509153904.sql h1:qjQLIMmKH3CqJ01uMbvfvB8aHct3JBkx5GPoWcqUStU=

app/controlplane/internal/data/ent/migrate/schema.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ var (
440440
{Name: "attestation_state", Type: field.TypeBytes, Nullable: true},
441441
{Name: "contract_revision_used", Type: field.TypeInt},
442442
{Name: "contract_revision_latest", Type: field.TypeInt},
443-
{Name: "robot_account_workflowruns", Type: field.TypeUUID, Nullable: true},
444443
{Name: "workflow_workflowruns", Type: field.TypeUUID, Nullable: true},
445444
{Name: "workflow_run_contract_version", Type: field.TypeUUID, Nullable: true},
446445
}
@@ -450,21 +449,15 @@ var (
450449
Columns: WorkflowRunsColumns,
451450
PrimaryKey: []*schema.Column{WorkflowRunsColumns[0]},
452451
ForeignKeys: []*schema.ForeignKey{
453-
{
454-
Symbol: "workflow_runs_robot_accounts_workflowruns",
455-
Columns: []*schema.Column{WorkflowRunsColumns[12]},
456-
RefColumns: []*schema.Column{RobotAccountsColumns[0]},
457-
OnDelete: schema.SetNull,
458-
},
459452
{
460453
Symbol: "workflow_runs_workflows_workflowruns",
461-
Columns: []*schema.Column{WorkflowRunsColumns[13]},
454+
Columns: []*schema.Column{WorkflowRunsColumns[12]},
462455
RefColumns: []*schema.Column{WorkflowsColumns[0]},
463456
OnDelete: schema.Cascade,
464457
},
465458
{
466459
Symbol: "workflow_runs_workflow_contract_versions_contract_version",
467-
Columns: []*schema.Column{WorkflowRunsColumns[14]},
460+
Columns: []*schema.Column{WorkflowRunsColumns[13]},
468461
RefColumns: []*schema.Column{WorkflowContractVersionsColumns[0]},
469462
OnDelete: schema.Cascade,
470463
},
@@ -603,9 +596,8 @@ func init() {
603596
WorkflowsTable.ForeignKeys[1].RefTable = WorkflowContractsTable
604597
WorkflowContractsTable.ForeignKeys[0].RefTable = OrganizationsTable
605598
WorkflowContractVersionsTable.ForeignKeys[0].RefTable = WorkflowContractsTable
606-
WorkflowRunsTable.ForeignKeys[0].RefTable = RobotAccountsTable
607-
WorkflowRunsTable.ForeignKeys[1].RefTable = WorkflowsTable
608-
WorkflowRunsTable.ForeignKeys[2].RefTable = WorkflowContractVersionsTable
599+
WorkflowRunsTable.ForeignKeys[0].RefTable = WorkflowsTable
600+
WorkflowRunsTable.ForeignKeys[1].RefTable = WorkflowContractVersionsTable
609601
ReferrerReferencesTable.ForeignKeys[0].RefTable = ReferrersTable
610602
ReferrerReferencesTable.ForeignKeys[1].RefTable = ReferrersTable
611603
ReferrerWorkflowsTable.ForeignKeys[0].RefTable = ReferrersTable

0 commit comments

Comments
 (0)