fix(db-postgres): start transaction in v2-v3 migration only after drizzle prompts to avoid timeout (#12302)

When running the v2-v3 migration you might receive prompts for renaming
columns. Since we start a transaction before, you might end up with a
fail if you don't answer within your transaction session period timeout.
This moves the `getTransaction` call after prompts were answered, since
we don't have a reason to start it earlier.
This commit is contained in:
Sasha
2025-05-05 16:20:30 +03:00
committed by GitHub
parent 3fb81ef43b
commit 2628b43639

View File

@@ -36,7 +36,6 @@ type Args = {
*/
export const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {
const adapter = payload.db as unknown as BasePostgresAdapter
const db = await getTransaction(adapter, req)
const dir = payload.db.migrationDir
// get the drizzle migrateUpSQL from drizzle using the last schema
@@ -89,6 +88,8 @@ export const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {
payload.logger.info(addColumnsStatement)
}
const db = await getTransaction(adapter, req)
await db.execute(sql.raw(addColumnsStatement))
for (const collection of payload.config.collections) {