diff --git a/packages/cli/src/commands/db/__tests__/revert.test.ts b/packages/cli/src/commands/db/__tests__/revert.test.ts index 463c9d617c..ce3911b2b6 100644 --- a/packages/cli/src/commands/db/__tests__/revert.test.ts +++ b/packages/cli/src/commands/db/__tests__/revert.test.ts @@ -170,3 +170,38 @@ test('revert the last migration if it has a down migration', async () => { expect(dataSource.undoLastMigration).toHaveBeenCalled(); expect(dataSource.destroy).toHaveBeenCalled(); }); + +test("don't use transaction if the last migration has transaction = false", async () => { + // + // ARRANGE + // + class TestMigration implements ReversibleMigration { + name = 'ReversibleMigration'; + + transaction = false as const; + + async up() {} + + async down() {} + } + + const migrationsInDb: Migration[] = [ + { id: 1, timestamp: Date.now(), name: 'ReversibleMigration' }, + ]; + const dataSource = mock({ migrations: [new TestMigration()] }); + + const migrationExecutor = mock(); + migrationExecutor.getExecutedMigrations.mockResolvedValue(migrationsInDb); + + // + // ACT + // + await main(logger, dataSource, migrationExecutor); + + // + // ASSERT + // + expect(dataSource.undoLastMigration).toHaveBeenCalledWith({ + transaction: 'none', + }); +}); diff --git a/packages/cli/src/commands/db/revert.ts b/packages/cli/src/commands/db/revert.ts index 7823506ee0..4510044405 100644 --- a/packages/cli/src/commands/db/revert.ts +++ b/packages/cli/src/commands/db/revert.ts @@ -55,7 +55,9 @@ export async function main( return; } - await connection.undoLastMigration(); + await connection.undoLastMigration({ + transaction: lastMigrationInstance.transaction === false ? 'none' : 'each', + }); await connection.destroy(); }