mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 11:49:59 +00:00
fix: Fix transaction handling for 'revert' command (#11145)
This commit is contained in:
@@ -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',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user