|
|
|
@ -342,10 +342,11 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
|
|
|
|
|
title: tn |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
let queryParams; |
|
|
|
|
let queryParams: any; |
|
|
|
|
try { |
|
|
|
|
queryParams = JSON.parse(oldModelRow.query_params); |
|
|
|
|
} catch (e) { |
|
|
|
|
queryParams = {} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -434,7 +435,8 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
|
|
|
|
|
aclOper.push(async () => this.modifyColumnNameInACL(tn, column.cno, column.cn)); |
|
|
|
|
|
|
|
|
|
// virtual views param update
|
|
|
|
|
for (const qp of virtualViewsParamsArr) { |
|
|
|
|
for (const qp of [queryParams, ...virtualViewsParamsArr]) { |
|
|
|
|
if (!qp) continue |
|
|
|
|
// @ts-ignore
|
|
|
|
|
const {filters, sortList, showFields} = qp; |
|
|
|
|
/* update sort field */ |
|
|
|
@ -533,8 +535,8 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
|
|
|
|
|
|
|
|
|
|
// update lookup columns
|
|
|
|
|
this.metas[mm.rtn].v?.forEach(v => { |
|
|
|
|
if (v.lk &&v.lk.ltn === tn && v.lk.lcn === column.cno) { |
|
|
|
|
relationTableMetas.add(this.metas[mm.tn]) |
|
|
|
|
if (v.lk && v.lk.ltn === tn && v.lk.lcn === column.cno) { |
|
|
|
|
relationTableMetas.add(this.metas[mm.rtn]) |
|
|
|
|
v.lk.lcn = column.cn; |
|
|
|
|
v.lk._lcn = column._cn; |
|
|
|
|
} |
|
|
|
@ -626,9 +628,9 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
|
|
|
|
|
if (newMeta.manyToMany?.length) { |
|
|
|
|
for (const mm of newMeta.manyToMany) { |
|
|
|
|
// filter out lookup columns which maps to current col
|
|
|
|
|
this.metas[mm.rtn].v=this.metas[mm.rtn].v?.filter(v => { |
|
|
|
|
this.metas[mm.rtn].v = this.metas[mm.rtn].v?.filter(v => { |
|
|
|
|
if (v.lk && v.lk.ltn === tn && v.lk.lcn === column.cn) { |
|
|
|
|
relationTableMetas.add(this.metas[mm.tn]) |
|
|
|
|
relationTableMetas.add(this.metas[mm.rtn]) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
@ -668,12 +670,27 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// update relation tables metadata
|
|
|
|
|
for (const relMeta of relationTableMetas) { |
|
|
|
|
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', { |
|
|
|
|
meta: JSON.stringify(relMeta) |
|
|
|
|
}, { |
|
|
|
|
title: relMeta.tn |
|
|
|
|
}); |
|
|
|
|
this.models[relMeta.tn] = this.getBaseModel(relMeta); |
|
|
|
|
XcCache.del([this.projectId, this.dbAlias, 'table', relMeta.tn].join('::')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', { |
|
|
|
|
meta: JSON.stringify(newMeta), |
|
|
|
|
...(queryParams ? {query_params: JSON.stringify(queryParams)} : {}) |
|
|
|
|
}, { |
|
|
|
|
title: tn |
|
|
|
|
}); |
|
|
|
|
XcCache.del([this.projectId, this.dbAlias, 'table', tn].join('::')); |
|
|
|
|
|
|
|
|
|
this.models[tn] = this.getBaseModel(newMeta); |
|
|
|
|
|
|
|
|
|
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_acl', { |
|
|
|
|
acl: JSON.stringify(acl) |
|
|
|
@ -691,21 +708,11 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
|
|
|
|
|
} |
|
|
|
|
this.baseLog(`onTableUpdate : Generating model instance for '%s' table`, tn) |
|
|
|
|
|
|
|
|
|
this.models[tn] = this.getBaseModel(newMeta); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await NcHelp.executeOperations(aclOper, this.connectionConfig.client); |
|
|
|
|
|
|
|
|
|
// update relation tables metadata
|
|
|
|
|
for (const relMeta of relationTableMetas) { |
|
|
|
|
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', { |
|
|
|
|
meta: JSON.stringify(relMeta) |
|
|
|
|
}, { |
|
|
|
|
title: relMeta.tn |
|
|
|
|
}); |
|
|
|
|
this.models[relMeta.tn] = this.getBaseModel(relMeta); |
|
|
|
|
XcCache.del([this.projectId, this.dbAlias, 'table', relMeta.tn].join('::')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -945,6 +952,9 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
|
|
|
|
|
|
|
|
|
|
protected initDbDriver(): void { |
|
|
|
|
if (!this.dbDriver) { |
|
|
|
|
if(this.projectBuilder?.prefix){ |
|
|
|
|
this.dbDriver = this.xcMeta.knex |
|
|
|
|
}else { |
|
|
|
|
if (this.connectionConfig?.connection?.ssl && typeof this.connectionConfig?.connection?.ssl === 'object') { |
|
|
|
|
if (this.connectionConfig.connection.ssl.caFilePath) { |
|
|
|
|
this.connectionConfig.connection.ssl.ca = fs |
|
|
|
@ -984,8 +994,8 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
|
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!this.sqlClient) { |
|
|
|
|
|
|
|
|
|
this.sqlClient = SqlClientFactory.create(this.connectionConfig) as MysqlClient; |
|
|
|
|
// close knex connection in sqlclient and reuse existing connection
|
|
|
|
|
this.sqlClient.knex.destroy(); |
|
|
|
|