Update foreign key references when dropping or renaming columns in alter table tests

This commit is contained in:
Stela Augustinova
2025-12-03 15:21:12 +01:00
parent c0287e49d8
commit 251609e274

View File

@@ -182,7 +182,15 @@ describe('Alter table', () => {
)( )(
'Drop column - %s - %s', 'Drop column - %s - %s',
testWrapper(async (conn, driver, column, engine) => { testWrapper(async (conn, driver, column, engine) => {
await testTableDiff(engine, conn, driver, tbl => (tbl.columns = tbl.columns.filter(x => x.columnName != column))); await testTableDiff(engine, conn, driver,
tbl => {
tbl.columns = tbl.columns.filter(x => x.columnName != column);
tbl.foreignKeys = tbl.foreignKeys.map(fk => ({
...fk,
columns: fk.columns.filter(col => col.columnName != column)
})).filter(fk => fk.columns.length > 0);
}
);
}) })
); );
@@ -205,7 +213,11 @@ describe('Alter table', () => {
engine, engine,
conn, conn,
driver, driver,
tbl => (tbl.columns = tbl.columns.map(x => (x.columnName == column ? { ...x, columnName: 'col_renamed' } : x))) tbl => {
tbl.columns = tbl.columns.map(x => (x.columnName == column ? { ...x, columnName: 'col_renamed' } : x));
tbl.foreignKeys = tbl.foreignKeys.map(fk => ({...fk, columns: fk.columns.map(col => col.columnName == column ? { ...col, columnName: 'col_renamed' } : col)
}));
}
); );
}) })
); );