mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
delete cascade
This commit is contained in:
parent
2c2b4fc08f
commit
aad39227b7
@ -333,6 +333,7 @@ export function getDeleteCascades(changeSet: ChangeSet, dbinfo: DatabaseInfo): C
|
|||||||
const allForeignKeys = _.flatten(dbinfo.tables.map(x => x.foreignKeys));
|
const allForeignKeys = _.flatten(dbinfo.tables.map(x => x.foreignKeys));
|
||||||
for (const baseCmd of changeSet.deletes) {
|
for (const baseCmd of changeSet.deletes) {
|
||||||
const table = dbinfo.tables.find(x => x.pureName == baseCmd.pureName && x.schemaName == baseCmd.schemaName);
|
const table = dbinfo.tables.find(x => x.pureName == baseCmd.pureName && x.schemaName == baseCmd.schemaName);
|
||||||
|
if (!table.primaryKey) continue;
|
||||||
const dependencies = allForeignKeys.filter(
|
const dependencies = allForeignKeys.filter(
|
||||||
x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName
|
x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName
|
||||||
);
|
);
|
||||||
@ -385,7 +386,7 @@ export function getDeleteCascades(changeSet: ChangeSet, dbinfo: DatabaseInfo): C
|
|||||||
conditions: [
|
conditions: [
|
||||||
extractCondition(baseCmd, 't2'),
|
extractCondition(baseCmd, 't2'),
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
...fk.columns.map(column => ({
|
...table.primaryKey.columns.map(column => ({
|
||||||
conditionType: 'binary',
|
conditionType: 'binary',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
left: {
|
left: {
|
||||||
@ -395,7 +396,7 @@ export function getDeleteCascades(changeSet: ChangeSet, dbinfo: DatabaseInfo): C
|
|||||||
},
|
},
|
||||||
right: {
|
right: {
|
||||||
exprType: 'column',
|
exprType: 'column',
|
||||||
columnName: column.refColumnName,
|
columnName: column.columnName,
|
||||||
source: {
|
source: {
|
||||||
name: {
|
name: {
|
||||||
pureName: fk.refTableName,
|
pureName: fk.refTableName,
|
||||||
@ -419,6 +420,17 @@ export function getDeleteCascades(changeSet: ChangeSet, dbinfo: DatabaseInfo): C
|
|||||||
}
|
}
|
||||||
resItem.commands.push(refCmd);
|
resItem.commands.push(refCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let resItem = res.find(x => x.title == baseCmd.pureName);
|
||||||
|
if (!resItem) {
|
||||||
|
resItem = {
|
||||||
|
title: baseCmd.pureName,
|
||||||
|
commands: [],
|
||||||
|
};
|
||||||
|
res.push(resItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
resItem.commands.push(deleteToSql(baseCmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -82,9 +82,16 @@
|
|||||||
<FormSubmit
|
<FormSubmit
|
||||||
value="OK"
|
value="OK"
|
||||||
disabled={isRecreated && !values.allowRecreate}
|
disabled={isRecreated && !values.allowRecreate}
|
||||||
on:click={() => {
|
on:click={e => {
|
||||||
closeCurrentModal();
|
closeCurrentModal();
|
||||||
onConfirm();
|
onConfirm(
|
||||||
|
e.detail.deleteReferencesCascade
|
||||||
|
? deleteCascadesScripts
|
||||||
|
.filter(({ script, title }) => e.detail[`deleteReferences_${title}`] !== false)
|
||||||
|
.map(({ script, title }) => script)
|
||||||
|
.join('\n')
|
||||||
|
: null
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<FormStyledButton type="button" value="Close" on:click={closeCurrentModal} />
|
<FormStyledButton type="button" value="Close" on:click={closeCurrentModal} />
|
||||||
|
Loading…
Reference in New Issue
Block a user