diff --git a/packages/nc-gui/components/project/spreadsheet/components/headerCell.vue b/packages/nc-gui/components/project/spreadsheet/components/headerCell.vue
index 775f2d1d43..747e37fc32 100644
--- a/packages/nc-gui/components/project/spreadsheet/components/headerCell.vue
+++ b/packages/nc-gui/components/project/spreadsheet/components/headerCell.vue
@@ -115,7 +115,7 @@
Do you want to delete '{{
- column.cn
+ column._cn
}}' column ?
diff --git a/packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue b/packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue
index 5670149810..af898d7196 100644
--- a/packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue
+++ b/packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue
@@ -82,7 +82,7 @@
Do you want to delete '{{
- column.cn
+ column._cn
}}' column ?
diff --git a/packages/nc-gui/components/project/tableTabs/logicGrpc.vue b/packages/nc-gui/components/project/tableTabs/logicGrpc.vue
index ff400b865d..8f78dcbcf2 100644
--- a/packages/nc-gui/components/project/tableTabs/logicGrpc.vue
+++ b/packages/nc-gui/components/project/tableTabs/logicGrpc.vue
@@ -256,11 +256,11 @@ export default {
}])
this.messages = tableMeta.messages
this.services = tableMeta.services
- if (tableMeta.schema_previous) {
- this.schemaHistory = JSON.parse(tableMeta.schema_previous).reverse()
- } else {
- this.schemaHistory = []
- }
+ // if (tableMeta.schema_previous) {
+ // this.schemaHistory = JSON.parse(tableMeta.schema_previous).reverse()
+ // } else {
+ // this.schemaHistory = []
+ // }
},
async loadRpcs() {
this.rpcServices = (await this.$store.dispatch('sqlMgr/ActSqlOp', [{
diff --git a/packages/nc-gui/components/project/tableTabs/logicRest.vue b/packages/nc-gui/components/project/tableTabs/logicRest.vue
index 5f219d200d..3f12ea7ced 100644
--- a/packages/nc-gui/components/project/tableTabs/logicRest.vue
+++ b/packages/nc-gui/components/project/tableTabs/logicRest.vue
@@ -322,11 +322,11 @@ export default {
tn: this.nodes.tn || this.nodes.view_name
}])
this.swaggerDoc = JSON.stringify(JSON.parse(tableMeta.schema), 0, 2)
- if (tableMeta.schema_previous) {
- this.swaggerDocHistory = JSON.parse(tableMeta.schema_previous).reverse().map(o => JSON.stringify(o, null, 2))
- } else {
- this.swaggerDocHistory = []
- }
+ // if (tableMeta.schema_previous) {
+ // this.swaggerDocHistory = JSON.parse(tableMeta.schema_previous).reverse().map(o => JSON.stringify(o, null, 2))
+ // } else {
+ // this.swaggerDocHistory = []
+ // }
},
async saveSwaggerDoc() {
this.edited = false
diff --git a/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts b/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
index ac7f82a9a9..9df47da72e 100644
--- a/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
+++ b/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
@@ -1389,7 +1389,7 @@ export default abstract class BaseApiBuilder implements XcDynami
continue;
}
- const tableMetaA = this.metas[meta.belongsTo[0].rtn];
+ const tableMetaA = this. metas[meta.belongsTo[0].rtn];
const tableMetaB = this.metas[meta.belongsTo[1].rtn];
/* // remove hasmany relation with associate table from tables
diff --git a/packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts b/packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts
index 05d5f7def6..9635e98761 100644
--- a/packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts
+++ b/packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts
@@ -112,7 +112,9 @@ export class GqlApiBuilder extends BaseApiBuilder implements XcMetaMgr {
}
});
- for (const {meta, id, title, schema_previous} of metas) {
+ for (const {meta, id, title,
+ // schema_previous
+ } of metas) {
const metaObj = JSON.parse(meta);
/* filter relation where this table is present */
const hasMany = metaObj.hasMany.filter(({enabled}) => enabled)
@@ -127,15 +129,15 @@ export class GqlApiBuilder extends BaseApiBuilder implements XcMetaMgr {
const newSchema = this.schemas[title] = GqlXcSchemaFactory.create(this.connectionConfig, this.generateRendererArgs(ctx)).getString();
if (oldSchema !== this.schemas[title]) {
// keep upto 5 schema backup on table update
- let previousSchemas = [oldSchema]
- if (schema_previous) {
- previousSchemas = [...JSON.parse(schema_previous), oldSchema].slice(-5);
- }
+ // const previousSchemas = [oldSchema]
+ // if (schema_previous) {
+ // previousSchemas = [...JSON.parse(schema_previous), oldSchema].slice(-5);
+ // }
this.log(`onToggleModelRelation : Updating and taking backup of schema for '%s' table`, title)
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
schema: newSchema,
- schema_previous: JSON.stringify(previousSchemas)
+ // schema_previous: JSON.stringify(previousSchemas)
}, {
id
});
@@ -1523,19 +1525,19 @@ export class GqlApiBuilder extends BaseApiBuilder implements XcMetaMgr {
if (oldSchema !== this.schemas[tn]) {
this.log(`onTableUpdate : Updating and taking backup of schema - '%s' table`, changeObj.tn);
- const oldModel = await this.xcMeta.metaGet(this.projectId, this.dbAlias, 'nc_models', {
- title: tn
- });
+ // const oldModel = await this.xcMeta.metaGet(this.projectId, this.dbAlias, 'nc_models', {
+ // title: tn
+ // });
// keep upto 5 schema backup on table update
- let previousSchemas = [oldSchema]
- if (oldModel.schema_previous) {
- previousSchemas = [...JSON.parse(oldModel.schema_previous), oldSchema].slice(-5);
- }
+ // let previousSchemas = [oldSchema]
+ // if (oldModel.schema_previous) {
+ // previousSchemas = [...JSON.parse(oldModel.schema_previous), oldSchema].slice(-5);
+ // }
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
schema: this.schemas[tn],
- schema_previous: JSON.stringify(previousSchemas)
+ // schema_previous: JSON.stringify(previousSchemas)
}, {
title: tn
});
@@ -1567,19 +1569,19 @@ export class GqlApiBuilder extends BaseApiBuilder implements XcMetaMgr {
this.log(`onViewUpdate : Updating and taking backup of schema - '%s' view`, viewName);
- const oldModel = await this.xcMeta.metaGet(this.projectId, this.dbAlias, 'nc_models', {
- title: viewName
- });
+ // const oldModel = await this.xcMeta.metaGet(this.projectId, this.dbAlias, 'nc_models', {
+ // title: viewName
+ // });
- // keep upto 5 schema backup on table update
- let previousSchemas = [oldSchema]
- if (oldModel.schema_previous) {
- previousSchemas = [...JSON.parse(oldModel.schema_previous), oldSchema].slice(-5);
- }
+ // // keep upto 5 schema backup on table update
+ // let previousSchemas = [oldSchema]
+ // if (oldModel.schema_previous) {
+ // previousSchemas = [...JSON.parse(oldModel.schema_previous), oldSchema].slice(-5);
+ // }
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
schema: meta.schema,
- schema_previous: JSON.stringify(previousSchemas)
+ // schema_previous: JSON.stringify(previousSchemas)
}, {
title: viewName
});
@@ -1641,19 +1643,19 @@ export class GqlApiBuilder extends BaseApiBuilder implements XcMetaMgr {
const newSchemaa = GqlXcSchemaFactory.create(this.connectionConfig, this.generateRendererArgs(ctx)).getString();
if (newSchemaa !== this.schemas[tn]) {
- const oldModel = await this.xcMeta.metaGet(this.projectId, this.dbAlias, 'nc_models', {
- title: tn
- });
+ // const oldModel = await this.xcMeta.metaGet(this.projectId, this.dbAlias, 'nc_models', {
+ // title: tn
+ // });
- this.log(`onToggleModels : Updating and taking backup of schema for '%s'`, tn);
- let previousSchemas = [this.schemas[tn]];
- if (oldModel.schema_previous) {
- previousSchemas = [...JSON.parse(oldModel.schema_previous), [this.schemas[tn]]].slice(-5);
- }
+ // this.log(`onToggleModels : Updating and taking backup of schema for '%s'`, tn);
+ // let previousSchemas = [this.schemas[tn]];
+ // if (oldModel.schema_previous) {
+ // previousSchemas = [...JSON.parse(oldModel.schema_previous), [this.schemas[tn]]].slice(-5);
+ // }
this.schemas[tn] = newSchemaa;
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
schema: this.schemas[tn],
- schema_previous: JSON.stringify(previousSchemas)
+ // schema_previous: JSON.stringify(previousSchemas)
}, {
title: tn
})
@@ -2019,19 +2021,19 @@ export class GqlApiBuilder extends BaseApiBuilder implements XcMetaMgr {
if (oldSchema !== this.schemas[tn]) {
// this.log(`onTableUpdate : Updating and taking backup of schema - '%s' table`, tn);
- const oldModel = await this.xcMeta.metaGet(this.projectId, this.dbAlias, 'nc_models', {
- title: tn
- });
+ // const oldModel = await this.xcMeta.metaGet(this.projectId, this.dbAlias, 'nc_models', {
+ // title: tn
+ // });
- // keep upto 5 schema backup on table update
- let previousSchemas = [oldSchema]
- if (oldModel.schema_previous) {
- previousSchemas = [...JSON.parse(oldModel.schema_previous), oldSchema].slice(-5);
- }
+ // // keep upto 5 schema backup on table update
+ // let previousSchemas = [oldSchema]
+ // if (oldModel.schema_previous) {
+ // previousSchemas = [...JSON.parse(oldModel.schema_previous), oldSchema].slice(-5);
+ // }
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
schema: this.schemas[tn],
- schema_previous: JSON.stringify(previousSchemas)
+ // schema_previous: JSON.stringify(previousSchemas)
}, {
title: tn,
type: 'table'
diff --git a/packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts b/packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
index 3e628a426f..a5b62da056 100644
--- a/packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
+++ b/packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
@@ -406,7 +406,7 @@ export default class NcMetaMgr {
const projectDetails = projectDetailsJSON && JSON.parse(projectDetailsJSON);
if (args.args.importsToCurrentProject) {
- await promisify(ncp)(path.join(this.config.toolDir, 'uploads', 'nc', projectDetails.id), path.join(this.config.toolDir, 'nc', projectId), {clobber:true})
+ await promisify(ncp)(path.join(this.config.toolDir, 'uploads', 'nc', projectDetails.id), path.join(this.config.toolDir, 'nc', projectId), {clobber: true})
} else {
// decrypt with old key and encrypt again with latest key
const projectConfig = JSON.parse(CryptoJS.AES.decrypt(projectDetails.config, projectDetails.key).toString(CryptoJS.enc.Utf8))
@@ -2413,6 +2413,7 @@ export default class NcMetaMgr {
}
+ // todo: transaction
protected async xcM2MRelationCreate(args: any, req): Promise {
const dbAlias = this.getDbAlias(args);
const projectId = this.getProjectId(args);
@@ -2529,7 +2530,7 @@ export default class NcMetaMgr {
}
});
}
- const outrel1 = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('n', {
+ const outrel1 = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('relationCreate', {
...args,
args: rel2Args
});
@@ -2677,45 +2678,54 @@ export default class NcMetaMgr {
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,
- foreignKeyName: rel1.fkn,
- type: 'bt',
- }
- }, req, false)
- await this.xcRelationColumnDelete({
- ...args,
- args: {
- parentTable: rel2.rtn,
- parentColumn: rel2.rcn,
- childTable: rel2.tn,
- childColumn: rel2.cn,
- foreignKeyName: rel2.fkn,
- type: 'bt',
- }
- }, req, false);
+ if (rel1) {
+ await this.xcRelationColumnDelete({
+ ...args,
+ args: {
+ parentTable: rel1.rtn,
+ parentColumn: rel1.rcn,
+ childTable: rel1.tn,
+ childColumn: rel1.cn,
+ foreignKeyName: rel1.fkn,
+ type: 'bt',
+ }
+ }, req, false)
+ }
+ if (rel2) {
+ await this.xcRelationColumnDelete({
+ ...args,
+ args: {
+ parentTable: rel2.rtn,
+ parentColumn: rel2.rcn,
+ childTable: rel2.tn,
+ childColumn: rel2.cn,
+ foreignKeyName: rel2.fkn,
+ type: 'bt',
+ }
+ }, req, false);
+ }
+ // ignore deleting table if it have more than 2 columns
+ if (assocMeta.columns.length === 2) {
- 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}
- });
+ 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}
+ });
+ }
}
}
diff --git a/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts b/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts
index 5d2a47ffc1..bde3054181 100644
--- a/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts
+++ b/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts
@@ -1473,17 +1473,17 @@ export class RestApiBuilder extends BaseApiBuilder {
});
const oldSwaggerDoc = JSON.parse(meta.schema);
- // keep upto 5 schema backup on table update
- let previousSchemas = [oldSwaggerDoc]
- if (meta.schema_previous) {
- previousSchemas = [...JSON.parse(meta.schema_previous), oldSwaggerDoc].slice(-5);
- }
+ // // keep upto 5 schema backup on table update
+ // let previousSchemas = [oldSwaggerDoc]
+ // if (meta.schema_previous) {
+ // previousSchemas = [...JSON.parse(meta.schema_previous), oldSwaggerDoc].slice(-5);
+ // }
oldSwaggerDoc.definitions = swaggerDoc.definitions;
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
schema: JSON.stringify(oldSwaggerDoc),
- schema_previous: JSON.stringify(previousSchemas)
+ // schema_previous: JSON.stringify(previousSchemas)
}, {
title: changeObj.tn,
type: 'table'
@@ -1779,17 +1779,17 @@ export class RestApiBuilder extends BaseApiBuilder {
});
const oldSwaggerDoc = JSON.parse(meta.schema);
- // keep upto 5 schema backup on table update
- let previousSchemas = [oldSwaggerDoc]
- if (meta.schema_previous) {
- previousSchemas = [...JSON.parse(meta.schema_previous), oldSwaggerDoc].slice(-5);
- }
+ // // keep upto 5 schema backup on table update
+ // let previousSchemas = [oldSwaggerDoc]
+ // if (meta.schema_previous) {
+ // previousSchemas = [...JSON.parse(meta.schema_previous), oldSwaggerDoc].slice(-5);
+ // }
oldSwaggerDoc.definitions = swaggerDoc.definitions;
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
schema: JSON.stringify(oldSwaggerDoc),
- schema_previous: JSON.stringify(previousSchemas)
+ // schema_previous: JSON.stringify(previousSchemas)
}, {
title: tn,
type: 'table'
@@ -1825,16 +1825,16 @@ export class RestApiBuilder extends BaseApiBuilder {
});
const oldSwaggerDoc = JSON.parse(meta.schema);
- // keep upto 5 schema backup on table update
- let previousSchemas = [oldSwaggerDoc]
- if (meta.schema_previous) {
- previousSchemas = [...JSON.parse(meta.schema_previous), oldSwaggerDoc].slice(-5);
- }
+ // // keep upto 5 schema backup on table update
+ // let previousSchemas = [oldSwaggerDoc]
+ // if (meta.schema_previous) {
+ // previousSchemas = [...JSON.parse(meta.schema_previous), oldSwaggerDoc].slice(-5);
+ // }
oldSwaggerDoc.definitions = swaggerDoc.definitions;
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
schema: JSON.stringify(oldSwaggerDoc),
- schema_previous: JSON.stringify(previousSchemas)
+ // schema_previous: JSON.stringify(previousSchemas)
}, {
title: metaObj.tn,
type: 'table'