-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Feature Description
Allow each individual migration to specify if it should be ran inside a transaction or not.
The Problem
Some operations cannot be ran inside a transaction (eg. CREATE INDEX CONCURRENTLY on postgresql). While the typeorm CLI does allow to specify a transaction argument on the migration:run command, this argument applies globally. This poses a problem when migrations are ran in a CI pipeline where we don't want to completely abandon the guarantees that wrapping a migration in a transaction gives us (safe rollback if something shall go wrong) and leaves no other resource other than running some migrations manually
The Solution
When running a migration the MigrationExecutor checks if the migration class defines a value for the transaction property in order to decide if this particular migration should be wrapped in a transaction or not. This value should take precedence over the transaction property of the MigrationExecutor.
There is an issue if the transaction argument is 'all' ie. all migrations should be executed within a single transaction, as there is no clear cut way to conciliate it with some migrations wanting to be ran outside transactions, so maybe the Migration's transaction property should only be honored if the MigrationExecutor's transaction is either 'each' in which case if a migration has transaction = false it is not wrapped in a migration, or MigrationExecutor's transaction is 'none' in which case only migrations which explicitly state it are wrapped in transactions.
Considered Alternatives
Additional Context
Relevant Database Driver(s)
-
aurora-data-api -
aurora-data-api-pg -
better-sqlite3 -
cockroachdb -
cordova -
expo -
mongodb -
mysql -
nativescript -
oracle -
postgres -
react-native -
sap -
sqlite -
sqlite-abstract -
sqljs -
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time, and I know how to start.
- Yes, I have the time, but I don't know how to start. I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.