Skip to content

Commit 610634a

Browse files
committed
Allows overriding transaction behavior in migrateUp
Adds the ability to override the `disableTransactions` setting when calling the `migrateUp` method, providing more granular control over transaction usage during migrations. This allows users to selectively enable or disable transactions for specific migration runs, regardless of the default setting on the `Migrator` instance.
1 parent 9c9a4b3 commit 610634a

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

test/node/src/migration.test.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ for (const dialect of DIALECTS) {
790790
expect(executedUpMethods2).to.eql(['migration2', 'migration4'])
791791
})
792792

793-
it('should not execute in transaction if disableTransactions is true', async () => {
793+
it('should not execute in transaction if disableTransactions is true on the `Migrator` instance', async () => {
794794
const [migrator, executedUpMethods] = createMigrations(['migration1'], {
795795
disableTransactions: true,
796796
})
@@ -806,7 +806,25 @@ for (const dialect of DIALECTS) {
806806
expect(transactionSpy.called).to.be.false
807807
})
808808

809-
it('should execute in transaction if disableTransactions is false and transactionDdl supported', async () => {
809+
it('should not execute in transaction if disableTransactions is true when calling `migrateUp`', async () => {
810+
const [migrator, executedUpMethods] = createMigrations(['migration1'], {
811+
disableTransactions: false,
812+
})
813+
814+
const { results } = await migrator.migrateUp({
815+
disableTransactions: true,
816+
})
817+
818+
expect(results).to.eql([
819+
{ migrationName: 'migration1', direction: 'Up', status: 'Success' },
820+
])
821+
822+
expect(executedUpMethods).to.eql(['migration1'])
823+
824+
expect(transactionSpy.called).to.be.false
825+
})
826+
827+
it('should execute in transaction if disableTransactions is false on the `Migrator` instance and transactionDdl supported', async () => {
810828
const [migrator, executedUpMethods] = createMigrations(['migration1'], {
811829
disableTransactions: false,
812830
})
@@ -825,6 +843,28 @@ for (const dialect of DIALECTS) {
825843
expect(transactionSpy.called).to.be.false
826844
}
827845
})
846+
847+
it('should execute in transaction if disableTransactions is false when calling `migrateUp` and transactionDdl supported', async () => {
848+
const [migrator, executedUpMethods] = createMigrations(['migration1'], {
849+
disableTransactions: true,
850+
})
851+
852+
const { results } = await migrator.migrateUp({
853+
disableTransactions: false,
854+
})
855+
856+
expect(results).to.eql([
857+
{ migrationName: 'migration1', direction: 'Up', status: 'Success' },
858+
])
859+
860+
expect(executedUpMethods).to.eql(['migration1'])
861+
862+
if (ctx.db.getExecutor().adapter.supportsTransactionalDdl) {
863+
expect(transactionSpy.called).to.be.true
864+
} else {
865+
expect(transactionSpy.called).to.be.false
866+
}
867+
})
828868
})
829869

830870
describe('migrateDown', () => {

0 commit comments

Comments
 (0)