delete casdcade: fixed loop preventing

This commit is contained in:
Jan Prochazka 2022-01-03 19:38:30 +01:00
parent 9250f2baaf
commit cb8d35c5c3

View File

@ -17,7 +17,8 @@ function processDependencies(
fkPath: ForeignKeyInfo[],
table: TableInfo,
baseCmd: ChangeSetItem,
dbinfo: DatabaseInfo
dbinfo: DatabaseInfo,
usedTables: string[]
) {
if (result.find(x => x.title == table.pureName)) return;
@ -28,8 +29,11 @@ function processDependencies(
for (const fk of dependencies) {
const depTable = dbinfo.tables.find(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName);
const subFkPath = [...fkPath, fk];
if (depTable && depTable.pureName != baseCmd.pureName) {
processDependencies(changeSet, result, allForeignKeys, subFkPath, depTable, baseCmd, dbinfo);
if (depTable && !usedTables.includes(depTable.pureName)) {
processDependencies(changeSet, result, allForeignKeys, subFkPath, depTable, baseCmd, dbinfo, [
...usedTables,
depTable.pureName,
]);
}
const refCmd: Delete = {
@ -119,7 +123,7 @@ export function getDeleteCascades(changeSet: ChangeSet, dbinfo: DatabaseInfo): C
const table = dbinfo.tables.find(x => x.pureName == baseCmd.pureName && x.schemaName == baseCmd.schemaName);
if (!table.primaryKey) continue;
processDependencies(changeSet, result, allForeignKeys, [], table, baseCmd, dbinfo);
processDependencies(changeSet, result, allForeignKeys, [], table, baseCmd, dbinfo, [table.pureName]);
// let resItem = result.find(x => x.title == baseCmd.pureName);
// if (!resItem) {