tada5hi/typeorm-extension

Feature: run migrations with transaction mode specified in data source options

mderriey opened this issue ยท 3 comments

Is your feature request related to a problem? Please describe.

Using createDatabase with DataSourceOptions that specify a value for migrationsTransactionMode ignores that value and runs with the default mode, which is to create a single transaction for all migrations, which causes issues on our end.

Describe the solution you'd like

When the library runs migrations on the database, it'd be great if it could honour the migrationsTransactionMode property if specified.

Describe alternatives you've considered

The workaround I'm using at the moment is to disable synchronization when using createDatabase (which is enabled by default), then new-up a DataSource manually and run the migrations.

Code I'd like to be able to use:

import { createDatabase, dropDatabase } from 'typeorm-extension'
import type { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions'

const dataSourceOptions: PostgresConnectionOptions = {
  [...],
  migrationsTransactionMode: 'each',
}

await createDatabase({
  options: dataSourceOptions,
  initialDatabase: 'my-test-database',
})

Code I'm currently using:

import { createDatabase, dropDatabase } from 'typeorm-extension'
import type { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions'
import { DataSource } from 'typeorm'

const dataSourceOptions: PostgresConnectionOptions = {
  [...],
  migrationsTransactionMode: 'each',
}

await createDatabase({
  options: dataSourceOptions,
  initialDatabase: 'my-test-database',
  // Explicitly disable synchronization
  synchronize: false,
})

// Run migrations manually
const migrationsDataSource = new DataSource(options)
await migrationsDataSource.initialize()
await migrationsDataSource.runMigrations({ transaction: dataSourceOptions.migrationsTransactionMode })
await migrationsDataSource.destroy()

Additional context

N/A

@mderriey Oh i'm sorry that the current behavior has caused problems for you ๐Ÿ˜”
As you noted, this option should be considered and I'm glad you opened a pr right away

๐ŸŽ‰ This issue has been resolved in version 2.4.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€