diff --git a/packages/core/src/migration/index.ts b/packages/core/src/migration/index.ts index 21ac88d9b..090e7748c 100644 --- a/packages/core/src/migration/index.ts +++ b/packages/core/src/migration/index.ts @@ -109,7 +109,9 @@ const runMigration = async (pool: DatabasePool, file: string) => { const { up } = await importMigration(file); try { - await up(pool); + await pool.transaction(async (connect) => { + await up(connect); + }); } catch (error: unknown) { if (error instanceof Error) { console.log(`${chalk.red('[migration]')} run ${file} failed: ${error.message}.`); diff --git a/packages/core/src/migration/types.ts b/packages/core/src/migration/types.ts index 71f1f964c..f750275d7 100644 --- a/packages/core/src/migration/types.ts +++ b/packages/core/src/migration/types.ts @@ -1,4 +1,4 @@ -import { DatabasePool } from 'slonik'; +import { DatabaseTransactionConnection } from 'slonik'; import { z } from 'zod'; export const databaseVersionGuard = z.object({ @@ -9,6 +9,6 @@ export const databaseVersionGuard = z.object({ export type DatabaseVersion = z.infer; export type MigrationScript = { - up: (pool: DatabasePool) => Promise; - down: (pool: DatabasePool) => Promise; + up: (connection: DatabaseTransactionConnection) => Promise; + down: (connection: DatabaseTransactionConnection) => Promise; };