Skip to content

Commit 88613a7

Browse files
authored
feat(project-version): Store total count of workflow runs for project version (chainloop-dev#1618)
Signed-off-by: Javier Rodriguez <[email protected]>
1 parent dab1f11 commit 88613a7

File tree

15 files changed

+364
-28
lines changed

15 files changed

+364
-28
lines changed

app/controlplane/pkg/biz/projectversion.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ import (
2626
)
2727

2828
type ProjectVersion struct {
29-
ID uuid.UUID
30-
Version string
29+
// ID is the UUID of the project version.
30+
ID uuid.UUID
31+
// Version is the version of the project.
32+
Version string
33+
// Prerelease indicates whether the version is a prerelease.
3134
Prerelease bool
32-
CreatedAt *time.Time
35+
// TotalWorkflowRuns is the total number of workflow runs for this version.
36+
TotalWorkflowRuns int
37+
// CreatedAt is the time when the project version was created.
38+
CreatedAt *time.Time
3339
}
3440

3541
type ProjectVersionRepo interface {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Modify "project_versions" table
2+
ALTER TABLE "project_versions" ADD COLUMN "workflow_run_count" bigint NOT NULL DEFAULT 0;
3+
4+
-- Update the "project_versions" table by adding the proper count of workflow runs for each project version
5+
UPDATE "project_versions" SET "workflow_run_count" = (
6+
SELECT COUNT(*)
7+
FROM "workflow_runs"
8+
WHERE "workflow_runs"."version_id" = "project_versions"."id"
9+
);

app/controlplane/pkg/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:Igi2AdQrKbr6iehJdtxkal0vZYJOo0Z7OpmB0/T9rk0=
1+
h1:9d3RI3C2m6UpE6ZBOK84CtuaGgIFhln44Ie2wW0xuS0=
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=
@@ -71,3 +71,4 @@ h1:Igi2AdQrKbr6iehJdtxkal0vZYJOo0Z7OpmB0/T9rk0=
7171
20241126182209.sql h1:01eeRbQxKYsjhEvafp1fL4kYJx4NoidwjcxWbWLlNak=
7272
20241129164322.sql h1:QYuxTg1P//afuTEzzopH/D6mexMm3UVuIIwlaxCWGOA=
7373
20241129170353.sql h1:9RmXI0seY855RHiJx1+tfd3iwf9R5HR+3EsWmZdH6nw=
74+
20241205150625.sql h1:D0Z2lbpsO+65zpt/stpIn4SFmd5M2AcbwXeopKeCeRQ=

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ var (
323323
{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
324324
{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
325325
{Name: "prerelease", Type: field.TypeBool, Default: true},
326+
{Name: "workflow_run_count", Type: field.TypeInt, Default: 0},
326327
{Name: "project_id", Type: field.TypeUUID},
327328
}
328329
// ProjectVersionsTable holds the schema information for the "project_versions" table.
@@ -333,7 +334,7 @@ var (
333334
ForeignKeys: []*schema.ForeignKey{
334335
{
335336
Symbol: "project_versions_projects_versions",
336-
Columns: []*schema.Column{ProjectVersionsColumns[5]},
337+
Columns: []*schema.Column{ProjectVersionsColumns[6]},
337338
RefColumns: []*schema.Column{ProjectsColumns[0]},
338339
OnDelete: schema.Cascade,
339340
},
@@ -342,7 +343,7 @@ var (
342343
{
343344
Name: "projectversion_version_project_id",
344345
Unique: true,
345-
Columns: []*schema.Column{ProjectVersionsColumns[1], ProjectVersionsColumns[5]},
346+
Columns: []*schema.Column{ProjectVersionsColumns[1], ProjectVersionsColumns[6]},
346347
Annotation: &entsql.IndexAnnotation{
347348
Where: "deleted_at IS NULL",
348349
},

app/controlplane/pkg/data/ent/mutation.go

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

app/controlplane/pkg/data/ent/projectversion.go

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

app/controlplane/pkg/data/ent/projectversion/projectversion.go

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

0 commit comments

Comments
 (0)