fix: Fix transaction handling for 'revert' command (#11145)
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions

This commit is contained in:
Tomi Turtiainen 2024-10-07 21:43:09 +03:00 committed by GitHub
parent 2bb1996738
commit a7823367f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 1 deletions

View file

@ -170,3 +170,38 @@ test('revert the last migration if it has a down migration', async () => {
expect(dataSource.undoLastMigration).toHaveBeenCalled(); expect(dataSource.undoLastMigration).toHaveBeenCalled();
expect(dataSource.destroy).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<DataSource>({ migrations: [new TestMigration()] });
const migrationExecutor = mock<MigrationExecutor>();
migrationExecutor.getExecutedMigrations.mockResolvedValue(migrationsInDb);
//
// ACT
//
await main(logger, dataSource, migrationExecutor);
//
// ASSERT
//
expect(dataSource.undoLastMigration).toHaveBeenCalledWith({
transaction: 'none',
});
});

View file

@ -55,7 +55,9 @@ export async function main(
return; return;
} }
await connection.undoLastMigration(); await connection.undoLastMigration({
transaction: lastMigrationInstance.transaction === false ? 'none' : 'each',
});
await connection.destroy(); await connection.destroy();
} }