Browse Source

fix: ignore user created associative table, remove schema and swagger json backup

re #496

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/498/head
Pranav C 3 years ago
parent
commit
24e98ed7d0
  1. 2
      packages/nc-gui/components/project/spreadsheet/components/headerCell.vue
  2. 2
      packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue
  3. 10
      packages/nc-gui/components/project/tableTabs/logicGrpc.vue
  4. 10
      packages/nc-gui/components/project/tableTabs/logicRest.vue
  5. 2
      packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
  6. 84
      packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts
  7. 86
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
  8. 36
      packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts

2
packages/nc-gui/components/project/spreadsheet/components/headerCell.vue

@ -115,7 +115,7 @@
<v-divider />
<v-card-text class="mt-4 title">
Do you want to delete <span class="font-weight-bold">'{{
column.cn
column._cn
}}'</span> column ?
</v-card-text>
<v-divider />

2
packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue

@ -82,7 +82,7 @@
<v-divider />
<v-card-text class="mt-4 title">
Do you want to delete <span class="font-weight-bold">'{{
column.cn
column._cn
}}'</span> column ?
</v-card-text>
<v-divider />

10
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', [{

10
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

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

@ -1389,7 +1389,7 @@ export default abstract class BaseApiBuilder<T extends Noco> 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

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

@ -112,7 +112,9 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> 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<Noco> 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<Noco> 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<Noco> 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<Noco> 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<Noco> 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'

86
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<any> {
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}
});
}
}
}

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

@ -1473,17 +1473,17 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
});
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<Noco> {
});
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<Noco> {
});
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'

Loading…
Cancel
Save