mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
feat(core): deploy migration in transaction mode (#1980)
This commit is contained in:
parent
d4fc7b3e5f
commit
9a89c1a200
2 changed files with 6 additions and 4 deletions
|
@ -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}.`);
|
||||
|
|
|
@ -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<typeof databaseVersionGuard>;
|
||||
|
||||
export type MigrationScript = {
|
||||
up: (pool: DatabasePool) => Promise<void>;
|
||||
down: (pool: DatabasePool) => Promise<void>;
|
||||
up: (connection: DatabaseTransactionConnection) => Promise<void>;
|
||||
down: (connection: DatabaseTransactionConnection) => Promise<void>;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue