mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
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
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:
parent
2bb1996738
commit
a7823367f1
|
@ -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<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',
|
||||
});
|
||||
});
|
||||
|
|
|
@ -55,7 +55,9 @@ export async function main(
|
|||
return;
|
||||
}
|
||||
|
||||
await connection.undoLastMigration();
|
||||
await connection.undoLastMigration({
|
||||
transaction: lastMigrationInstance.transaction === false ? 'none' : 'each',
|
||||
});
|
||||
await connection.destroy();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue