|
|
|
@ -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> { |
|
|
|
|
const dbAlias = this.getDbAlias(args); |
|
|
|
|
const projectId = this.getProjectId(args); |
|
|
|
|
// this.xcMeta.startTransaction();
|
|
|
|
|
// try {
|
|
|
|
|
const dbAlias = this.getDbAlias(args); |
|
|
|
|
const projectId = this.getProjectId(args); |
|
|
|
|
|
|
|
|
|
// const parent = await this.xcMeta.metaGet(projectId, dbAlias, 'nc_models', {
|
|
|
|
|
// title: args.args.parentTable
|
|
|
|
|
// });
|
|
|
|
|
// // @ts-ignore
|
|
|
|
|
// const parentMeta = JSON.parse(parent.meta);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
// todo: compare column
|
|
|
|
|
switch (args.args.type) { |
|
|
|
|
case 'bt': |
|
|
|
|
case 'hm': |
|
|
|
|
const child = await this.xcMeta.metaGet(projectId, dbAlias, 'nc_models', { |
|
|
|
|
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 parent = await this.xcMeta.metaGet(projectId, dbAlias, 'nc_models', {
|
|
|
|
|
// title: args.args.parentTable
|
|
|
|
|
// });
|
|
|
|
|
// // @ts-ignore
|
|
|
|
|
// const parentMeta = JSON.parse(parent.meta);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
// todo: compare column
|
|
|
|
|
switch (args.args.type) { |
|
|
|
|
case 'bt': |
|
|
|
|
case 'hm': |
|
|
|
|
const child = await this.xcMeta.metaGet(projectId, dbAlias, 'nc_models', { |
|
|
|
|
title: args.args.childTable |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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 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} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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 = { |
|
|
|
|
...args, |
|
|
|
|
args: { |
|
|
|
|
columns, |
|
|
|
|
originalColumns, |
|
|
|
|
tn: childMeta.tn, |
|
|
|
|
}, |
|
|
|
|
args: assocMeta, |
|
|
|
|
api: 'tableDelete', |
|
|
|
|
sqlOpPlus: true, |
|
|
|
|
api: 'tableUpdate' |
|
|
|
|
} |
|
|
|
|
const out = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('tableUpdate', opArgs); |
|
|
|
|
}; |
|
|
|
|
const out = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('tableDelete', opArgs); |
|
|
|
|
|
|
|
|
|
if (this.listener) { |
|
|
|
|
await this.listener({ |
|
|
|
@ -2533,57 +2582,15 @@ export default class NcMetaMgr {
|
|
|
|
|
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;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|