0
Fork 0
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:
wangsijie 2022-09-23 10:22:13 +08:00 committed by GitHub
parent d4fc7b3e5f
commit 9a89c1a200
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -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}.`);

View file

@ -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>;
};