diff --git a/apps/backend/prisma/migrations/20251003231948_enable_and_pin_apps/migration.sql b/apps/backend/prisma/migrations/20251003231948_enable_and_pin_apps/migration.sql index 499bc95af..8e465e140 100644 --- a/apps/backend/prisma/migrations/20251003231948_enable_and_pin_apps/migration.sql +++ b/apps/backend/prisma/migrations/20251003231948_enable_and_pin_apps/migration.sql @@ -1,5 +1,9 @@ -- Create temporary index to speed up the migration -CREATE INDEX IF NOT EXISTS "temp_eco_config_apps_idx" ON "EnvironmentConfigOverride" USING GIN ("config"); +-- SPLIT_STATEMENT_SENTINEL +-- SINGLE_STATEMENT_SENTINEL +-- RUN_OUTSIDE_TRANSACTION_SENTINEL +CREATE INDEX CONCURRENTLY IF NOT EXISTS "temp_eco_config_apps_idx" ON "EnvironmentConfigOverride" USING GIN ("config"); +-- SPLIT_STATEMENT_SENTINEL -- SPLIT_STATEMENT_SENTINEL -- SINGLE_STATEMENT_SENTINEL diff --git a/apps/backend/src/auto-migrations/index.tsx b/apps/backend/src/auto-migrations/index.tsx index 510590a22..5d2736bb3 100644 --- a/apps/backend/src/auto-migrations/index.tsx +++ b/apps/backend/src/auto-migrations/index.tsx @@ -123,8 +123,10 @@ export async function applyMigrations(options: { } for (const statement of migration.sql.split('SPLIT_STATEMENT_SENTINEL')) { + const txOrPrismaClient = statement.includes('RUN_OUTSIDE_TRANSACTION_SENTINEL') ? options.prismaClient : tx; + if (statement.includes('SINGLE_STATEMENT_SENTINEL')) { - const res = await tx.$queryRaw`${Prisma.raw(statement)}`; + const res = await txOrPrismaClient.$queryRaw`${Prisma.raw(statement)}`; if (statement.includes('CONDITIONALLY_REPEAT_MIGRATION_SENTINEL')) { if (!Array.isArray(res)) { throw new StackAssertionError("Expected an array as a return value of repeat condition", { res }); @@ -138,7 +140,7 @@ export async function applyMigrations(options: { } if (res[0].should_repeat_migration) { if (options.logging) { - console.log(`Migration ${migration.migrationName} should be repeated`); + console.log(`Migration ${migration.migrationName} requested to be repeated. This is normal and *not* indicative of a problem.`); } // Commit the transaction and continue re-running the migration return; @@ -146,7 +148,7 @@ export async function applyMigrations(options: { } } } else { - await tx.$executeRaw` + await txOrPrismaClient.$executeRaw` DO $$ BEGIN ${Prisma.raw(statement)}