Browse Source

feat: metasync(wip)

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/894/head
Pranav C 3 years ago
parent
commit
233671a498
  1. 142
      packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
  2. 6
      packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts
  3. 5
      packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts
  4. 6
      packages/nocodb/src/lib/sqlMgr/code/models/xc/BaseModelXcMeta.ts

142
packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts

@ -208,31 +208,32 @@ export default abstract class BaseApiBuilder<T extends Noco>
public async onTableDelete( public async onTableDelete(
tn: string, tn: string,
extras?: { ignoreRelations?: boolean } extras?: { ignoreVirtualRelations?: boolean; ignoreViews?: boolean }
): Promise<void> { ): Promise<void> {
this.baseLog(`onTableDelete : '%s'`, tn); this.baseLog(`onTableDelete : '%s'`, tn);
XcCache.del([this.projectId, this.dbAlias, 'table', tn].join('::')); XcCache.del([this.projectId, this.dbAlias, 'table', tn].join('::'));
if (!extras?.ignoreRelations) await this.xcMeta.metaDelete(
await this.xcMeta.metaDelete( this.projectId,
this.projectId, this.dbAlias,
this.dbAlias, 'nc_relations',
'nc_relations', null,
null, {
{ _or: [
_or: [ {
{ tn: {
tn: { eq: tn
eq: tn
}
},
{
rtn: {
eq: tn
}
} }
] },
} {
); rtn: {
eq: tn
}
}
],
...(extras?.ignoreVirtualRelations ? { type: { eq: 'virtual' } } : {})
}
);
await this.deleteTableNameInACL(tn); await this.deleteTableNameInACL(tn);
await this.xcMeta.metaDelete( await this.xcMeta.metaDelete(
@ -355,7 +356,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
/* update fieldsOrder */ /* update fieldsOrder */
const index = fieldsOrder.indexOf(alias); const index = fieldsOrder.indexOf(alias);
if (index > -1) { if (index > -1) {
fieldsOrder.splice(index, 0); fieldsOrder.splice(index, 1);
} }
/* update formView params */ /* update formView params */
@ -1030,7 +1031,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
/* update fieldsOrder */ /* update fieldsOrder */
const index = fieldsOrder.indexOf(column.cno); const index = fieldsOrder.indexOf(column.cno);
if (index > -1) { if (index > -1) {
fieldsOrder.splice(index, 0); fieldsOrder.splice(index, 1);
} }
/* update formView params */ /* update formView params */
@ -1531,7 +1532,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
/* update fieldsOrder */ /* update fieldsOrder */
const index = fieldsOrder.indexOf(alias); const index = fieldsOrder.indexOf(alias);
if (index > -1) { if (index > -1) {
fieldsOrder.splice(index, 0); fieldsOrder.splice(index, 1);
} }
/* update formView params */ /* update formView params */
@ -2957,7 +2958,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
} }
public async onTableMetaRecreate(tableName: string): Promise<void> { public async onTableMetaRecreate(tableName: string): Promise<void> {
const meta = this.getMeta(tableName); const oldMeta = this.getMeta(tableName);
const virtualRelations = await this.xcMeta.metaList( const virtualRelations = await this.xcMeta.metaList(
this.projectId, this.projectId,
@ -2966,7 +2967,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
{ {
xcCondition: { xcCondition: {
virtual: true, type: 'virtual',
_or: [ _or: [
{ {
tn: { tn: {
@ -3003,16 +3004,95 @@ export default abstract class BaseApiBuilder<T extends Noco>
rel.id rel.id
); );
} }
// todo : handle query params
const oldModelRow = await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_models',
{ title: tableName }
);
await this.onTableDelete(tableName, { await this.onTableDelete(tableName, {
ignoreRelations: true, ignoreVirtualRelations: true,
ignoreViews: true ignoreViews: true
} as any); } as any);
// todo : handle query params let queryParams: any;
// todo : handle query para try {
queryParams = JSON.parse(oldModelRow.query_params);
} catch (e) {
queryParams = {};
}
const {
virtualViews,
virtualViewsParamsArr
} = await this.extractSharedAndVirtualViewsParams(tableName);
await this.onTableCreate(tableName, { oldMeta: oldMeta });
const meta = this.getMeta(tableName);
for (const oldColumn of oldMeta.columns) {
if (meta.columns.find(c => c.c === 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.cno
);
if (sIndex > -1) {
sortList.splice(sIndex, 1);
}
/* update show field */
if (oldColumn.cno in showFields) {
delete showFields[oldColumn.cno];
}
/* update filters */
if (
filters &&
JSON.stringify(filters)?.includes(`"${oldColumn.cno}"`)
) {
filters.splice(0, filters.length);
}
/* update fieldsOrder */
const index = fieldsOrder.indexOf(oldColumn.cno);
if (index > -1) {
fieldsOrder.splice(index, 1);
}
await this.onTableCreate(tableName, { oldMeta: meta }); /* update formView params */
// extraViewParams.formParams.fields
if (extraViewParams?.formParams?.fields?.[oldColumn.cno]) {
delete extraViewParams.formParams.fields[oldColumn.cno];
}
}
}
await this.updateSharedAndVirtualViewsParams(
virtualViewsParamsArr,
virtualViews
);
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
{
query_params: JSON.stringify(queryParams)
},
{ title: tableName, type: 'table' }
);
} }
protected async getOrderVal(): Promise<number> { protected async getOrderVal(): Promise<number> {

6
packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts

@ -199,10 +199,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
await this.reInitializeGraphqlEndpoint(); await this.reInitializeGraphqlEndpoint();
} }
public async onTableDelete( public async onTableDelete(tn: string, extras?: any): Promise<void> {
tn: string,
extras?: { ignoreRelations?: boolean }
): Promise<void> {
await super.onTableDelete(tn, extras); await super.onTableDelete(tn, extras);
this.log(`onTableDelete : '%s' `, tn); this.log(`onTableDelete : '%s' `, tn);
delete this.models[tn]; delete this.models[tn];
@ -735,6 +732,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
/* Get all relations */ /* Get all relations */
/* let [ /* let [
relations, relations,
// eslint-disable-next-line prefer-const
missingRelations missingRelations
] = await this.getRelationsAndMissingRelations(); ] = await this.getRelationsAndMissingRelations();
relations = relations.concat(missingRelations);*/ relations = relations.concat(missingRelations);*/

5
packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts

@ -883,10 +883,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
}); });
} }
public async onTableDelete( public async onTableDelete(tn: string, extras?: any): Promise<void> {
tn: string,
extras?: { ignoreRelations?: boolean }
): Promise<void> {
await super.onTableDelete(tn, extras); await super.onTableDelete(tn, extras);
this.log("onTableDelete : '%s'", tn); this.log("onTableDelete : '%s'", tn);
try { try {

6
packages/nocodb/src/lib/sqlMgr/code/models/xc/BaseModelXcMeta.ts

@ -105,6 +105,12 @@ abstract class BaseModelXcMeta extends BaseRender {
_cn: `${bt._rtn} <= ${bt._tn}` _cn: `${bt._rtn} <= ${bt._tn}`
})) }))
]; ];
// const oldVirtualCols = this.ctx?.oldMeta?.v || [];
// for (const oldVCol of oldVirtualCols) {
// if
// }
} }
public mapDefaultPrimaryValue(columnsArr: any[]): void { public mapDefaultPrimaryValue(columnsArr: any[]): void {

Loading…
Cancel
Save