Skip to content

Commit 70ead41

Browse files
committed
Clean up branch config overrides after completion
1 parent 15b5336 commit 70ead41

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

‎.github/workflows/db-migration-backwards-compatibility.yaml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ name: DB migrations are backwards-compatible with main branch
22

33
on:
44
push:
5-
branches:
5+
branches-ignore:
66
- main
7-
- dev
87
pull_request:
98

109
concurrency:
1110
group: ${{ github.workflow }}-${{ github.ref }}
12-
cancel-in-progress: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/dev' }}
11+
cancel-in-progress: ${{ github.ref != 'refs/heads/dev' }}
1312

1413
jobs:
1514
check-migrations-changed:

apps/backend/prisma/migrations/20260201230001_env_to_branch_config/migration.sql renamed to apps/backend/prisma/migrations/20260201230002_env_to_branch_config/migration.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,43 @@ SELECT COUNT(*) > 0 AS should_repeat_migration FROM inserted;
229229
-- Clean up temporary index
230230
DROP INDEX IF EXISTS "temp_eco_branch_transfer_idx";
231231

232+
-- Safety net: find any env configs that still have branch-level fields (like apps.installed.authentication.enabled)
233+
-- and process them. This should only affect projects that were modified during the migration.
234+
-- SPLIT_STATEMENT_SENTINEL
235+
-- SINGLE_STATEMENT_SENTINEL
236+
WITH leftover_configs AS (
237+
SELECT eco."projectId", eco."branchId", eco."config", eco."createdAt"
238+
FROM "EnvironmentConfigOverride" eco
239+
WHERE eco."config" ? 'apps.installed.authentication.enabled'
240+
),
241+
upserted_branch AS (
242+
INSERT INTO "BranchConfigOverride" ("projectId", "branchId", "createdAt", "updatedAt", "config", "source")
243+
SELECT
244+
lc."projectId",
245+
lc."branchId",
246+
lc."createdAt",
247+
CURRENT_TIMESTAMP,
248+
-- Merge with existing branch config if present
249+
COALESCE(
250+
(SELECT bco."config" FROM "BranchConfigOverride" bco
251+
WHERE bco."projectId" = lc."projectId" AND bco."branchId" = lc."branchId"),
252+
'{}'::jsonb
253+
) || temp_filter_branch_config(lc."config"),
254+
'{"type": "unlinked"}'::jsonb
255+
FROM leftover_configs lc
256+
ON CONFLICT ("projectId", "branchId") DO UPDATE
257+
SET "config" = "BranchConfigOverride"."config" || temp_filter_branch_config(EXCLUDED."config"),
258+
"updatedAt" = CURRENT_TIMESTAMP
259+
RETURNING "projectId", "branchId"
260+
)
261+
UPDATE "EnvironmentConfigOverride" eco
262+
SET "config" = temp_filter_env_only_config(eco."config"),
263+
"updatedAt" = CURRENT_TIMESTAMP
264+
FROM leftover_configs lc
265+
WHERE eco."projectId" = lc."projectId"
266+
AND eco."branchId" = lc."branchId";
267+
-- SPLIT_STATEMENT_SENTINEL
268+
232269
-- Clean up temporary functions
233270
DROP FUNCTION IF EXISTS temp_filter_env_only_config(JSONB);
234271
DROP FUNCTION IF EXISTS temp_filter_branch_config(JSONB);

0 commit comments

Comments
 (0)