|
|
|
@ -141,8 +141,18 @@ export default async function(this: BaseApiBuilder<any> | any) {
|
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
if (delete this.metas[tn]) delete this.metas[tn]; |
|
|
|
|
if (delete this.models[tn]) delete this.models[tn]; |
|
|
|
|
if (this.metas?.[tn]) delete this.metas[tn]; |
|
|
|
|
if (this.models?.[tn]) delete this.models[tn]; |
|
|
|
|
if (this.resolvers?.[tn]) delete this.resolvers[tn]; |
|
|
|
|
if (this.schemas?.[tn]) delete this.schemas[tn]; |
|
|
|
|
await this.xcMeta.metaDelete( |
|
|
|
|
this.projectId, |
|
|
|
|
this.dbAlias, |
|
|
|
|
'nc_resolvers', |
|
|
|
|
{ |
|
|
|
|
title: tn |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case XcMetaDiffType.TABLE_COLUMN_ADD: |
|
|
|
@ -199,11 +209,11 @@ export default async function(this: BaseApiBuilder<any> | any) {
|
|
|
|
|
|
|
|
|
|
/* update sort field */ |
|
|
|
|
/* const sIndex = (sortList || []).findIndex( |
|
|
|
|
v => v.field === oldColumn._cn |
|
|
|
|
); |
|
|
|
|
if (sIndex > -1) { |
|
|
|
|
sortList.splice(sIndex, 1); |
|
|
|
|
}*/ |
|
|
|
|
v => v.field === oldColumn._cn |
|
|
|
|
); |
|
|
|
|
if (sIndex > -1) { |
|
|
|
|
sortList.splice(sIndex, 1); |
|
|
|
|
}*/ |
|
|
|
|
for (const sort of sortList || []) { |
|
|
|
|
if ( |
|
|
|
|
sort?.field === oldColumn.cn || |
|
|
|
@ -221,12 +231,12 @@ export default async function(this: BaseApiBuilder<any> | any) {
|
|
|
|
|
/* update filters */ |
|
|
|
|
// todo: remove only corresponding filter and compare field name
|
|
|
|
|
/* if ( |
|
|
|
|
filters && |
|
|
|
|
(JSON.stringify(filters)?.includes(`"${oldColumn.cn}"`) || |
|
|
|
|
JSON.stringify(filters)?.includes(`"${oldColumn._cn}"`)) |
|
|
|
|
) { |
|
|
|
|
filters.splice(0, filters.length); |
|
|
|
|
}*/ |
|
|
|
|
filters && |
|
|
|
|
(JSON.stringify(filters)?.includes(`"${oldColumn.cn}"`) || |
|
|
|
|
JSON.stringify(filters)?.includes(`"${oldColumn._cn}"`)) |
|
|
|
|
) { |
|
|
|
|
filters.splice(0, filters.length); |
|
|
|
|
}*/ |
|
|
|
|
for (const filter of filters) { |
|
|
|
|
if ( |
|
|
|
|
filter?.field === oldColumn.cn || |
|
|
|
@ -328,8 +338,8 @@ export default async function(this: BaseApiBuilder<any> | any) {
|
|
|
|
|
db_type: this.connectionConfig?.client |
|
|
|
|
// todo: get these info
|
|
|
|
|
/* dr: , |
|
|
|
|
ur: onUpdate, |
|
|
|
|
fkn*/ |
|
|
|
|
ur: onUpdate, |
|
|
|
|
fkn*/ |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
populateParams.tableNames.push({ tn: change.tn }); |
|
|
|
@ -656,11 +666,11 @@ export default async function(this: BaseApiBuilder<any> | any) {
|
|
|
|
|
|
|
|
|
|
/* update sort field */ |
|
|
|
|
/* const sIndex = (sortList || []).findIndex( |
|
|
|
|
v => v.field === oldColumn._cn |
|
|
|
|
); |
|
|
|
|
if (sIndex > -1) { |
|
|
|
|
sortList.splice(sIndex, 1); |
|
|
|
|
}*/ |
|
|
|
|
v => v.field === oldColumn._cn |
|
|
|
|
); |
|
|
|
|
if (sIndex > -1) { |
|
|
|
|
sortList.splice(sIndex, 1); |
|
|
|
|
}*/ |
|
|
|
|
for (const sort of sortList || []) { |
|
|
|
|
if ( |
|
|
|
|
sort?.field === oldColumn.cn || |
|
|
|
@ -678,12 +688,12 @@ export default async function(this: BaseApiBuilder<any> | any) {
|
|
|
|
|
/* update filters */ |
|
|
|
|
// todo: remove only corresponding filter and compare field name
|
|
|
|
|
/* if ( |
|
|
|
|
filters && |
|
|
|
|
(JSON.stringify(filters)?.includes(`"${oldColumn.cn}"`) || |
|
|
|
|
JSON.stringify(filters)?.includes(`"${oldColumn._cn}"`)) |
|
|
|
|
) { |
|
|
|
|
filters.splice(0, filters.length); |
|
|
|
|
}*/ |
|
|
|
|
filters && |
|
|
|
|
(JSON.stringify(filters)?.includes(`"${oldColumn.cn}"`) || |
|
|
|
|
JSON.stringify(filters)?.includes(`"${oldColumn._cn}"`)) |
|
|
|
|
) { |
|
|
|
|
filters.splice(0, filters.length); |
|
|
|
|
}*/ |
|
|
|
|
for (const filter of filters) { |
|
|
|
|
if ( |
|
|
|
|
filter?.field === oldColumn.cn || |
|
|
|
@ -784,178 +794,3 @@ export default async function(this: BaseApiBuilder<any> | any) {
|
|
|
|
|
|
|
|
|
|
return populateParams; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// public async onTableMetaRecreate(tableName: string): Promise<void> {
|
|
|
|
|
// this.baseLog(`onTableMetaRecreate : '%s'`, tableName);
|
|
|
|
|
// const oldMeta = this.getMeta(tableName);
|
|
|
|
|
//
|
|
|
|
|
// const virtualRelations = await this.xcMeta.metaList(
|
|
|
|
|
// this.projectId,
|
|
|
|
|
// this.dbAlias,
|
|
|
|
|
// 'nc_relations',
|
|
|
|
|
// {
|
|
|
|
|
// xcCondition: {
|
|
|
|
|
// _or: [
|
|
|
|
|
// {
|
|
|
|
|
// tn: {
|
|
|
|
|
// eq: tableName
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// {
|
|
|
|
|
// rtn: {
|
|
|
|
|
// eq: tableName
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// ]
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// );
|
|
|
|
|
// const colListRef = {};
|
|
|
|
|
// const tableList =
|
|
|
|
|
// (await this.getSqlClient()?.tableList())?.data?.list || [];
|
|
|
|
|
//
|
|
|
|
|
// colListRef[tableName] = await this.getColumnList(tableName);
|
|
|
|
|
//
|
|
|
|
|
// // @ts-ignore
|
|
|
|
|
// const relations = await this.getRelationList();
|
|
|
|
|
//
|
|
|
|
|
// for (const vCol of oldMeta.v || []) {
|
|
|
|
|
// if (vCol.lk) {
|
|
|
|
|
// }
|
|
|
|
|
// if (vCol.rl) {
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// for (const rel of virtualRelations) {
|
|
|
|
|
// colListRef[rel.tn] =
|
|
|
|
|
// colListRef[rel.tn] || (await this.getColumnList(rel.tn));
|
|
|
|
|
// colListRef[rel.rtn] =
|
|
|
|
|
// colListRef[rel.rtn] || (await this.getColumnList(rel.rtn));
|
|
|
|
|
//
|
|
|
|
|
// // todo: compare with real relation list
|
|
|
|
|
// if (
|
|
|
|
|
// !(
|
|
|
|
|
// tableList.find(t => t.tn === rel.rtn) &&
|
|
|
|
|
// tableList.find(t => t.tn === rel.tn) &&
|
|
|
|
|
// colListRef[rel.tn].find(t => t.cn === rel.cn) &&
|
|
|
|
|
// colListRef[rel.rtn].find(t => t.cn === rel.rcn)
|
|
|
|
|
// )
|
|
|
|
|
// )
|
|
|
|
|
// await this.xcMeta.metaDelete(
|
|
|
|
|
// this.projectId,
|
|
|
|
|
// this.dbAlias,
|
|
|
|
|
// 'nc_relations',
|
|
|
|
|
// rel.id
|
|
|
|
|
// );
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // todo : handle query params
|
|
|
|
|
// const oldModelRow = await this.xcMeta.metaGet(
|
|
|
|
|
// this.projectId,
|
|
|
|
|
// this.dbAlias,
|
|
|
|
|
// 'nc_models',
|
|
|
|
|
// { title: tableName }
|
|
|
|
|
// );
|
|
|
|
|
//
|
|
|
|
|
// await this.onTableDelete(tableName, {
|
|
|
|
|
// ignoreRelations: true,
|
|
|
|
|
// ignoreViews: true
|
|
|
|
|
// } as any);
|
|
|
|
|
//
|
|
|
|
|
// let queryParams: any;
|
|
|
|
|
// try {
|
|
|
|
|
// queryParams = JSON.parse(oldModelRow.query_params);
|
|
|
|
|
// } catch (e) {
|
|
|
|
|
// queryParams = {};
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// const {
|
|
|
|
|
// virtualViews,
|
|
|
|
|
// virtualViewsParamsArr
|
|
|
|
|
// } = await this.extractSharedAndVirtualViewsParams(tableName);
|
|
|
|
|
//
|
|
|
|
|
// for (const oldColumn of oldMeta.columns) {
|
|
|
|
|
// if (colListRef[tableName].find(c => c.cn === oldColumn.cn)) continue;
|
|
|
|
|
// addErrorOnColumnDeleteInFormula({
|
|
|
|
|
// virtualColumns: oldMeta.v,
|
|
|
|
|
// columnName: oldColumn.cn
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// await this.onTableCreate(tableName, { oldMeta });
|
|
|
|
|
//
|
|
|
|
|
// const meta = this.getMeta(tableName);
|
|
|
|
|
//
|
|
|
|
|
// for (const oldColumn of oldMeta.columns) {
|
|
|
|
|
// if (meta.columns.find(c => c.cn === oldColumn.cn)) continue;
|
|
|
|
|
//
|
|
|
|
|
// // virtual views param update
|
|
|
|
|
// for (const qp of [queryParams, ...virtualViewsParamsArr]) {
|
|
|
|
|
// if (!qp) continue;
|
|
|
|
|
//
|
|
|
|
|
// // @ts-ignore
|
|
|
|
|
// const {
|
|
|
|
|
// filters = {},
|
|
|
|
|
// sortList = [],
|
|
|
|
|
// showFields = {},
|
|
|
|
|
// fieldsOrder = [],
|
|
|
|
|
// extraViewParams = {}
|
|
|
|
|
// } = qp;
|
|
|
|
|
//
|
|
|
|
|
// /* update sort field */
|
|
|
|
|
// const sIndex = (sortList || []).findIndex(
|
|
|
|
|
// v => v.field === oldColumn._cn
|
|
|
|
|
// );
|
|
|
|
|
// if (sIndex > -1) {
|
|
|
|
|
// sortList.splice(sIndex, 1);
|
|
|
|
|
// }
|
|
|
|
|
// /* update show field */
|
|
|
|
|
// if (oldColumn.cn in showFields || oldColumn._cn in showFields) {
|
|
|
|
|
// delete showFields[oldColumn.cn];
|
|
|
|
|
// delete showFields[oldColumn._cn];
|
|
|
|
|
// }
|
|
|
|
|
// /* update filters */
|
|
|
|
|
// // todo: remove only corresponding filter and compare field name
|
|
|
|
|
// if (
|
|
|
|
|
// filters &&
|
|
|
|
|
// (JSON.stringify(filters)?.includes(`"${oldColumn.cn}"`) ||
|
|
|
|
|
// JSON.stringify(filters)?.includes(`"${oldColumn._cn}"`))
|
|
|
|
|
// ) {
|
|
|
|
|
// filters.splice(0, filters.length);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /* update fieldsOrder */
|
|
|
|
|
// let index = fieldsOrder.indexOf(oldColumn.cn);
|
|
|
|
|
// if (index > -1) {
|
|
|
|
|
// fieldsOrder.splice(index, 1);
|
|
|
|
|
// }
|
|
|
|
|
// index = fieldsOrder.indexOf(oldColumn._cn);
|
|
|
|
|
// if (index > -1) {
|
|
|
|
|
// fieldsOrder.splice(index, 1);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /* update formView params */
|
|
|
|
|
// // extraViewParams.formParams.fields
|
|
|
|
|
// if (extraViewParams?.formParams?.fields?.[oldColumn.cn]) {
|
|
|
|
|
// delete extraViewParams.formParams.fields[oldColumn.cn];
|
|
|
|
|
// }
|
|
|
|
|
// if (extraViewParams?.formParams?.fields?.[oldColumn._cn]) {
|
|
|
|
|
// delete extraViewParams.formParams.fields[oldColumn._cn];
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// await this.updateSharedAndVirtualViewsParams(
|
|
|
|
|
// virtualViewsParamsArr,
|
|
|
|
|
// virtualViews
|
|
|
|
|
// );
|
|
|
|
|
// await this.xcMeta.metaUpdate(
|
|
|
|
|
// this.projectId,
|
|
|
|
|
// this.dbAlias,
|
|
|
|
|
// 'nc_models',
|
|
|
|
|
// {
|
|
|
|
|
// query_params: JSON.stringify(queryParams)
|
|
|
|
|
// },
|
|
|
|
|
// { title: tableName, type: 'table' }
|
|
|
|
|
// );
|
|
|
|
|
// }
|
|
|
|
|