Skip to content

Commit

Permalink
feat: run migrations with specified transaction mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mderriey committed Dec 16, 2022
1 parent f6421b9 commit 3e7f9a5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/database/utils/schema.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { DataSource, DataSourceOptions, InstanceChecker } from 'typeorm';

export async function setupDatabaseSchema(input: DataSource | DataSourceOptions) {
let dataSource : DataSource;
let dataSource: DataSource;
let options: DataSourceOptions;

if (InstanceChecker.isDataSource(input)) {
dataSource = input;
options = dataSource.options;
} else {
dataSource = new DataSource(input);
options = input;
dataSource = new DataSource(options);
}

if (!dataSource.isInitialized) {
Expand All @@ -21,7 +24,7 @@ export async function setupDatabaseSchema(input: DataSource | DataSourceOptions)
}

if (migrationsCount > 0) {
await dataSource.runMigrations();
await dataSource.runMigrations({ transaction: options.migrationsTransactionMode });
} else {
await dataSource.synchronize(false);
}
Expand Down

0 comments on commit 3e7f9a5

Please sign in to comment.