Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,5 @@ All commits must meet these criteria:
Code reviews are required for all submissions via GitHub pull requests.
- make sure golang code is always formatted and golang-ci-lint is run
- I do not want you to be in the co-author signoff
- when the schema is changed, run make generate, do not create a migration explicitly
- when the schema is changed, run make generate, do not create a migration explicitly
- do not add generated by claude code in PR
4 changes: 3 additions & 1 deletion app/controlplane/pkg/biz/projectversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ type ProjectVersion struct {
CreatedAt *time.Time
// ReleasedAt is the time when the version was released.
ReleasedAt *time.Time
ProjectID uuid.UUID
// LastRunAt is the time when the last workflow run occurred for this version.
LastRunAt *time.Time
ProjectID uuid.UUID
}

type ProjectVersionRepo interface {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Modify "project_versions" table
ALTER TABLE "project_versions" ADD COLUMN "last_run_at" timestamptz NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
-- Backfill last_run_at field from existing workflow runs
-- This migration populates the last_run_at timestamp for project versions
-- based on the most recent workflow run for each version

DO $$
DECLARE
batch_size INTEGER := 50;
total_remaining INTEGER := 0;
BEGIN
-- Get initial count of project versions that need updating
-- (those with workflow runs but no last_run_at timestamp)
SELECT COUNT(DISTINCT pv.id)
INTO total_remaining
FROM project_versions pv
WHERE pv.last_run_at IS NULL
AND pv.deleted_at IS NULL
AND EXISTS (
SELECT 1 FROM workflow_runs wr
WHERE wr.version_id = pv.id
);

-- Log the initial count
RAISE NOTICE 'Starting backfill of last_run_at for % project versions', total_remaining;

-- Loop until no more rows remain
WHILE total_remaining > 0 LOOP
-- Update a batch of project versions with their latest workflow run timestamp
WITH versions_to_update AS (
SELECT pv.id
FROM project_versions pv
WHERE pv.last_run_at IS NULL
AND pv.deleted_at IS NULL
AND EXISTS (
SELECT 1 FROM workflow_runs wr
WHERE wr.version_id = pv.id
)
LIMIT batch_size
),
latest_runs AS (
SELECT
wr.version_id,
MAX(COALESCE(wr.finished_at, wr.created_at)) as latest_timestamp
FROM workflow_runs wr
INNER JOIN versions_to_update vtu ON wr.version_id = vtu.id
GROUP BY wr.version_id
)
UPDATE project_versions pv
SET last_run_at = lr.latest_timestamp
FROM latest_runs lr
WHERE pv.id = lr.version_id;

-- Update the remaining count
SELECT COUNT(DISTINCT pv.id)
INTO total_remaining
FROM project_versions pv
WHERE pv.last_run_at IS NULL
AND pv.deleted_at IS NULL
AND EXISTS (
SELECT 1 FROM workflow_runs wr
WHERE wr.version_id = pv.id
);

-- Log progress
IF total_remaining > 0 THEN
RAISE NOTICE 'Remaining project versions to backfill: %', total_remaining;
END IF;
END LOOP;

RAISE NOTICE 'Backfill of last_run_at completed successfully';
END $$;
4 changes: 3 additions & 1 deletion app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
h1:zMUQdCsdxlu5WHgd4G0cKNp4VzU0ViSDSSMojr38oXQ=
h1:SbJMyd1Na23ALCFwTq0rcVW1zSPsD4bVBvBuO1xOfuA=
20230706165452_init-schema.sql h1:VvqbNFEQnCvUVyj2iDYVQQxDM0+sSXqocpt/5H64k8M=
20230710111950-cas-backend.sql h1:A8iBuSzZIEbdsv9ipBtscZQuaBp3V5/VMw7eZH6GX+g=
20230712094107-cas-backends-workflow-runs.sql h1:a5rzxpVGyd56nLRSsKrmCFc9sebg65RWzLghKHh5xvI=
Expand Down Expand Up @@ -113,3 +113,5 @@ h1:zMUQdCsdxlu5WHgd4G0cKNp4VzU0ViSDSSMojr38oXQ=
20250827093032.sql h1:K+XDWewSLoGBM+zjkBMag3mMQFFQyoQ9SePzfRxC694=
20250902095134.sql h1:e1DP8uYf/CX7RCiCF+E2/TKXiFUR6EUQBPy0wh5Xxl0=
20250908160222.sql h1:bNjptbt2xPpSXqa4eVuWkMnovHt9LMkiakoGrFGZJ0g=
20251001215533.sql h1:+IdTm9OSW1r5nDH1fX2hpia/q0UzklPrDy3SDN3S0dg=
20251001215625.sql h1:adcp5r8CoL/JCfNgNZxBvY5pczlEHFH/IX64g/ji/4s=
5 changes: 3 additions & 2 deletions app/controlplane/pkg/data/ent/migrate/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ var (
{Name: "prerelease", Type: field.TypeBool, Default: true},
{Name: "workflow_run_count", Type: field.TypeInt, Default: 0},
{Name: "released_at", Type: field.TypeTime, Nullable: true},
{Name: "last_run_at", Type: field.TypeTime, Nullable: true},
{Name: "latest", Type: field.TypeBool, Default: false},
{Name: "project_id", Type: field.TypeUUID},
}
Expand All @@ -500,7 +501,7 @@ var (
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "project_versions_projects_versions",
Columns: []*schema.Column{ProjectVersionsColumns[9]},
Columns: []*schema.Column{ProjectVersionsColumns[10]},
RefColumns: []*schema.Column{ProjectsColumns[0]},
OnDelete: schema.Cascade,
},
Expand All @@ -509,7 +510,7 @@ var (
{
Name: "projectversion_version_project_id",
Unique: true,
Columns: []*schema.Column{ProjectVersionsColumns[1], ProjectVersionsColumns[9]},
Columns: []*schema.Column{ProjectVersionsColumns[1], ProjectVersionsColumns[10]},
Annotation: &entsql.IndexAnnotation{
Where: "deleted_at IS NULL",
},
Expand Down
75 changes: 74 additions & 1 deletion app/controlplane/pkg/data/ent/mutation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion app/controlplane/pkg/data/ent/projectversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading