|
|
@ -2455,75 +2455,124 @@ export default class NcMetaMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// todo : transaction
|
|
|
|
// todo : transaction in sql client
|
|
|
|
protected async xcRelationColumnDelete(args: any, req, deleteColumn = true): Promise<any> { |
|
|
|
protected async xcRelationColumnDelete(args: any, req, deleteColumn = true): Promise<any> { |
|
|
|
const dbAlias = this.getDbAlias(args); |
|
|
|
// this.xcMeta.startTransaction();
|
|
|
|
const projectId = this.getProjectId(args); |
|
|
|
// try {
|
|
|
|
|
|
|
|
const dbAlias = this.getDbAlias(args); |
|
|
|
|
|
|
|
const projectId = this.getProjectId(args); |
|
|
|
|
|
|
|
|
|
|
|
// const parent = await this.xcMeta.metaGet(projectId, dbAlias, 'nc_models', {
|
|
|
|
// const parent = await this.xcMeta.metaGet(projectId, dbAlias, 'nc_models', {
|
|
|
|
// title: args.args.parentTable
|
|
|
|
// title: args.args.parentTable
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// // @ts-ignore
|
|
|
|
// // @ts-ignore
|
|
|
|
// const parentMeta = JSON.parse(parent.meta);
|
|
|
|
// const parentMeta = JSON.parse(parent.meta);
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
// todo: compare column
|
|
|
|
// todo: compare column
|
|
|
|
switch (args.args.type) { |
|
|
|
switch (args.args.type) { |
|
|
|
case 'bt': |
|
|
|
case 'bt': |
|
|
|
case 'hm': |
|
|
|
case 'hm': |
|
|
|
const child = await this.xcMeta.metaGet(projectId, dbAlias, 'nc_models', { |
|
|
|
const child = await this.xcMeta.metaGet(projectId, dbAlias, 'nc_models', { |
|
|
|
title: args.args.childTable |
|
|
|
title: args.args.childTable |
|
|
|
}); |
|
|
|
|
|
|
|
const childMeta = JSON.parse(child.meta); |
|
|
|
|
|
|
|
const relation = childMeta.belongsTo.find(bt => bt.rtn === args.args.parentTable); |
|
|
|
|
|
|
|
// todo: virtual relation delete
|
|
|
|
|
|
|
|
if(relation){ |
|
|
|
|
|
|
|
const opArgs = { |
|
|
|
|
|
|
|
...args, |
|
|
|
|
|
|
|
args: { |
|
|
|
|
|
|
|
childColumn: relation.cn, |
|
|
|
|
|
|
|
childTable: relation.tn, |
|
|
|
|
|
|
|
parentTable: relation.rtn, |
|
|
|
|
|
|
|
parentColumn: relation.rcn |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
api: 'relationDelete', |
|
|
|
|
|
|
|
sqlOpPlus: true, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
let out; |
|
|
|
|
|
|
|
if (relation?.type === 'virtual') { |
|
|
|
|
|
|
|
opArgs.api = 'xcVirtualRelationDelete'; |
|
|
|
|
|
|
|
out = await this.xcVirtualRelationDelete(opArgs, req); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
out = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('relationDelete', opArgs); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.listener) { |
|
|
|
|
|
|
|
await this.listener({ |
|
|
|
|
|
|
|
req: opArgs, |
|
|
|
|
|
|
|
res: out, |
|
|
|
|
|
|
|
user: req.user, |
|
|
|
|
|
|
|
ctx: {req} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
const childMeta = JSON.parse(child.meta); |
|
|
|
} |
|
|
|
const relation = childMeta.belongsTo.find(bt => bt.rtn === args.args.parentTable); |
|
|
|
if (deleteColumn) { |
|
|
|
// todo: virtual relation delete
|
|
|
|
const originalColumns = childMeta.columns; |
|
|
|
if (relation) { |
|
|
|
const columns = childMeta.columns.map(c => ({ |
|
|
|
const opArgs = { |
|
|
|
...c, ...(relation.cn === c.cn ? { |
|
|
|
...args, |
|
|
|
altered: 4, |
|
|
|
args: { |
|
|
|
cno: c.cn |
|
|
|
childColumn: relation.cn, |
|
|
|
} : {cno: c.cn}) |
|
|
|
childTable: relation.tn, |
|
|
|
})) |
|
|
|
parentTable: relation.rtn, |
|
|
|
|
|
|
|
parentColumn: relation.rcn |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
api: 'relationDelete', |
|
|
|
|
|
|
|
sqlOpPlus: true, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
let out; |
|
|
|
|
|
|
|
if (relation?.type === 'virtual') { |
|
|
|
|
|
|
|
opArgs.api = 'xcVirtualRelationDelete'; |
|
|
|
|
|
|
|
out = await this.xcVirtualRelationDelete(opArgs, req); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
out = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('relationDelete', opArgs); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.listener) { |
|
|
|
|
|
|
|
await this.listener({ |
|
|
|
|
|
|
|
req: opArgs, |
|
|
|
|
|
|
|
res: out, |
|
|
|
|
|
|
|
user: req.user, |
|
|
|
|
|
|
|
ctx: {req} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (deleteColumn) { |
|
|
|
|
|
|
|
const originalColumns = childMeta.columns; |
|
|
|
|
|
|
|
const columns = childMeta.columns.map(c => ({ |
|
|
|
|
|
|
|
...c, ...(relation.cn === c.cn ? { |
|
|
|
|
|
|
|
altered: 4, |
|
|
|
|
|
|
|
cno: c.cn |
|
|
|
|
|
|
|
} : {cno: c.cn}) |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const opArgs = { |
|
|
|
|
|
|
|
...args, |
|
|
|
|
|
|
|
args: { |
|
|
|
|
|
|
|
columns, |
|
|
|
|
|
|
|
originalColumns, |
|
|
|
|
|
|
|
tn: childMeta.tn, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
sqlOpPlus: true, |
|
|
|
|
|
|
|
api: 'tableUpdate' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const out = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('tableUpdate', opArgs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.listener) { |
|
|
|
|
|
|
|
await this.listener({ |
|
|
|
|
|
|
|
req: opArgs, |
|
|
|
|
|
|
|
res: out, |
|
|
|
|
|
|
|
user: req.user, |
|
|
|
|
|
|
|
ctx: {req} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'mm': { |
|
|
|
|
|
|
|
const assoc = await this.xcMeta.metaGet(projectId, dbAlias, 'nc_models', { |
|
|
|
|
|
|
|
title: args.args.assocTable |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
const assocMeta = JSON.parse(assoc.meta); |
|
|
|
|
|
|
|
const rel1 = assocMeta.belongsTo.find(bt => bt.rtn === args.args.parentTable) |
|
|
|
|
|
|
|
const rel2 = assocMeta.belongsTo.find(bt => bt.rtn === args.args.childTable) |
|
|
|
|
|
|
|
await this.xcRelationColumnDelete({ |
|
|
|
|
|
|
|
...args, |
|
|
|
|
|
|
|
args: { |
|
|
|
|
|
|
|
parentTable: rel1.rtn, |
|
|
|
|
|
|
|
parentColumn: rel1.rcn, |
|
|
|
|
|
|
|
childTable: rel1.tn, |
|
|
|
|
|
|
|
childColumn: rel1.cn, |
|
|
|
|
|
|
|
type: 'bt', |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, req, false) |
|
|
|
|
|
|
|
await this.xcRelationColumnDelete({ |
|
|
|
|
|
|
|
...args, |
|
|
|
|
|
|
|
args: { |
|
|
|
|
|
|
|
parentTable: rel2.rtn, |
|
|
|
|
|
|
|
parentColumn: rel2.rcn, |
|
|
|
|
|
|
|
childTable: rel2.tn, |
|
|
|
|
|
|
|
childColumn: rel2.cn, |
|
|
|
|
|
|
|
type: 'bt', |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, req, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const opArgs = { |
|
|
|
const opArgs = { |
|
|
|
...args, |
|
|
|
...args, |
|
|
|
args: { |
|
|
|
args: assocMeta, |
|
|
|
columns, |
|
|
|
api: 'tableDelete', |
|
|
|
originalColumns, |
|
|
|
|
|
|
|
tn: childMeta.tn, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
sqlOpPlus: true, |
|
|
|
sqlOpPlus: true, |
|
|
|
api: 'tableUpdate' |
|
|
|
}; |
|
|
|
} |
|
|
|
const out = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('tableDelete', opArgs); |
|
|
|
const out = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('tableUpdate', opArgs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.listener) { |
|
|
|
if (this.listener) { |
|
|
|
await this.listener({ |
|
|
|
await this.listener({ |
|
|
@ -2533,57 +2582,15 @@ export default class NcMetaMgr { |
|
|
|
ctx: {req} |
|
|
|
ctx: {req} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'mm': { |
|
|
|
|
|
|
|
const assoc = await this.xcMeta.metaGet(projectId, dbAlias, 'nc_models', { |
|
|
|
|
|
|
|
title: args.args.assocTable |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
const assocMeta = JSON.parse(assoc.meta); |
|
|
|
|
|
|
|
const rel1 = assocMeta.belongsTo.find(bt => bt.rtn === args.args.parentTable) |
|
|
|
|
|
|
|
const rel2 = assocMeta.belongsTo.find(bt => bt.rtn === args.args.childTable) |
|
|
|
|
|
|
|
await this.xcRelationColumnDelete({ |
|
|
|
|
|
|
|
...args, |
|
|
|
|
|
|
|
args: { |
|
|
|
|
|
|
|
parentTable: rel1.rtn, |
|
|
|
|
|
|
|
parentColumn: rel1.rcn, |
|
|
|
|
|
|
|
childTable: rel1.tn, |
|
|
|
|
|
|
|
childColumn: rel1.cn, |
|
|
|
|
|
|
|
type: 'bt', |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, req, false) |
|
|
|
|
|
|
|
await this.xcRelationColumnDelete({ |
|
|
|
|
|
|
|
...args, |
|
|
|
|
|
|
|
args: { |
|
|
|
|
|
|
|
parentTable: rel2.rtn, |
|
|
|
|
|
|
|
parentColumn: rel2.rcn, |
|
|
|
|
|
|
|
childTable: rel2.tn, |
|
|
|
|
|
|
|
childColumn: rel2.cn, |
|
|
|
|
|
|
|
type: 'bt', |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, req, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const opArgs = { |
|
|
|
|
|
|
|
...args, |
|
|
|
|
|
|
|
args: assocMeta, |
|
|
|
|
|
|
|
api: 'tableDelete', |
|
|
|
|
|
|
|
sqlOpPlus: true, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
const out = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('tableDelete', opArgs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.listener) { |
|
|
|
|
|
|
|
await this.listener({ |
|
|
|
|
|
|
|
req: opArgs, |
|
|
|
|
|
|
|
res: out, |
|
|
|
|
|
|
|
user: req.user, |
|
|
|
|
|
|
|
ctx: {req} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
// this.xcMeta.commit()
|
|
|
|
} |
|
|
|
// } catch (e) {
|
|
|
|
|
|
|
|
// this.xcMeta.rollback(e)
|
|
|
|
|
|
|
|
// throw e;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|