mirror of
https://github.com/knex/knex.git
synced 2026-01-05 19:47:55 +00:00
Allow enabling/disabling transaction per-migration
Not just disabling transaction per-migration, but also enabling it in case transactions were turned globally off with config.disableTransactions.
This commit is contained in:
parent
3d85822a28
commit
b1f2c258df
@ -192,6 +192,18 @@ export default class Migrator {
|
||||
});
|
||||
}
|
||||
|
||||
// If transaction conf for a single migration is defined, use that.
|
||||
// Otherwise, rely on the common config. This allows enabling/disabling
|
||||
// transaction for a single migration by will, regardless of the common
|
||||
// config.
|
||||
_useTransaction(migration, allTransactionsDisabled) {
|
||||
var singleTransactionValue = _.get(migration, 'config.transaction');
|
||||
|
||||
return _.isBoolean(singleTransactionValue) ?
|
||||
singleTransactionValue :
|
||||
!allTransactionsDisabled;
|
||||
}
|
||||
|
||||
// Runs a batch of `migrations` in a specified `direction`,
|
||||
// saving the appropriate database information as the migrations are run.
|
||||
_waterfallBatch(batchNo, migrations, direction) {
|
||||
@ -206,10 +218,10 @@ export default class Migrator {
|
||||
|
||||
// We're going to run each of the migrations in the current "up"
|
||||
current = current.then(() => {
|
||||
if (disableTransactions) {
|
||||
return warnPromise(migration[direction](knex, Promise), name)
|
||||
if (this._useTransaction(migration, disableTransactions)) {
|
||||
return this._transaction(migration, direction, name)
|
||||
}
|
||||
return this._transaction(migration, direction, name)
|
||||
return warnPromise(migration[direction](knex, Promise), name)
|
||||
})
|
||||
.then(() => {
|
||||
log.push(path.join(directory, name));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user