Browse Source

feat: upgrade migrations

Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
pull/341/head
Pranav C 3 years ago
parent
commit
f4e5729350
  1. 2
      packages/nocodb/src/example/docker.ts
  2. 19
      packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
  3. 62
      packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts
  4. 2
      packages/nocodb/src/lib/sqlMgr/code/models/xc/BaseModelXcMeta.ts
  5. 3
      packages/nocodb/src/lib/sqlMgr/code/models/xc/ModelXcMetaFactory.ts
  6. 2
      packages/nocodb/src/lib/sqlMgr/code/routes/xc-ts/ExpressXcTsRoutes.ts

2
packages/nocodb/src/example/docker.ts

@ -1,5 +1,5 @@
import Noco from "../lib/noco/Noco"; import Noco from "../lib/noco/Noco";
process.env.NC_VERSION = '0009044';
import express from 'express'; import express from 'express';
import cors from 'cors'; import cors from 'cors';

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

@ -668,7 +668,7 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
const NC_VERSIONS = [ const NC_VERSIONS = [
{name: '0009000', handler: null}, {name: '0009000', handler: null},
{name: '0009044', handler: this.xcUpManyToMany} {name: '0009044', handler: this.ncUpManyToMany}
] ]
if (!await this.xcMeta?.knex?.schema?.hasTable?.('nc_store')) { if (!await this.xcMeta?.knex?.schema?.hasTable?.('nc_store')) {
return; return;
@ -1660,22 +1660,29 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
} }
private async xcUpManyToMany(): Promise<any> { protected async ncUpManyToMany(): Promise<any> {
const metas = await this.xcMeta.metaList(this.projectId, this.dbAlias, 'xc_models', { const models = await this.xcMeta.metaList(this.projectId, this.dbAlias, 'nc_models', {
fields: ['meta'] fields: ['meta']
}); });
if (!models.length) {
return
}
const metas = [];
// add virtual columns for relations // add virtual columns for relations
for (const {meta: metaJson} of metas) { for (const metaObj of models) {
const meta = JSON.parse(metaJson.meta); const meta = JSON.parse(metaObj.meta);
metas.push(meta);
const ctx = this.generateContextForTable(meta.tn, meta.columns, [], meta.hasMany, meta.belongsTo, meta.type, meta._tn); const ctx = this.generateContextForTable(meta.tn, meta.columns, [], meta.hasMany, meta.belongsTo, meta.type, meta._tn);
meta.v = ModelXcMetaFactory.create(this.connectionConfig, {dir: '', ctx, filename: ''}).getVitualColumns(); meta.v = ModelXcMetaFactory.create(this.connectionConfig, {dir: '', ctx, filename: ''}).getVitualColumns();
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'xc_models', { ModelXcMetaFactory.create(this.connectionConfig, {}).mapDefaultPrimaryValue(meta.columns);
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
meta: JSON.stringify(meta) meta: JSON.stringify(meta)
}, {title: meta.tn}) }, {title: meta.tn})
} }
// generate many to many relations an columns // generate many to many relations an columns
await this.getManyToManyRelations(); await this.getManyToManyRelations();
return metas;
} }
} }

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

@ -1,13 +1,3 @@
// import {
// ExpressXcTsRoutes,
// ExpressXcTsRoutesBt,
// ExpressXcTsRoutesHm,
// ModelXcMetaFactory,
// SwaggerXc,
// SwaggerXcHm,
// SwaggerXcBt
// } from 'nc-help';
import {RestCtrl} from "./RestCtrl"; import {RestCtrl} from "./RestCtrl";
import {RestCtrlBelongsTo} from "./RestCtrlBelongsTo"; import {RestCtrlBelongsTo} from "./RestCtrlBelongsTo";
import {RestCtrlHasMany} from "./RestCtrlHasMany"; import {RestCtrlHasMany} from "./RestCtrlHasMany";
@ -59,7 +49,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
this.xcMeta = xcMeta; this.xcMeta = xcMeta;
} }
public async init():Promise<void>{ public async init(): Promise<void> {
await super.init(); await super.init();
await this.loadRoutes(null); await this.loadRoutes(null);
} }
@ -1684,6 +1674,56 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
}) })
} }
protected async ncUpManyToMany(): Promise<any> {
const metas = await super.ncUpManyToMany();
if (!metas) {
return;
}
for (const meta of metas) {
const ctx = this.generateContextForTable(meta.tn, meta.columns, [], meta.hasMany, meta.belongsTo, meta.type, meta._tn);
/* create routes for table */
const routes = new ExpressXcTsRoutes({dir: '', ctx, filename: ''}).getObjectWithoutFunctions();
/* create nc_routes, add new routes or update order */
const routesInsertion = routes.map((route, i) => {
return async () => {
if (!await this.xcMeta.metaGet(this.projectId, this.dbAlias, 'nc_routes', {
path: route.path,
tn: meta.tn,
title: meta.tn,
type: route.type
})) {
await this.xcMeta.metaInsert(this.projectId, this.dbAlias, 'nc_routes', {
acl: JSON.stringify(route.acl),
handler: JSON.stringify(route.handler),
order: i,
path: route.path,
tn: meta.tn,
title: meta.tn,
type: route.type,
})
} else {
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_routes', {
order: i,
}, {
path: route.path,
tn: meta.tn,
title: meta.tn,
type: route.type
})
}
}
});
await NcHelp.executeOperations(routesInsertion, this.connectionConfig.client);
}
// add new routes
}
} }

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

@ -33,7 +33,7 @@ abstract class BaseModelXcMeta extends BaseRender {
]; ];
} }
protected mapDefaultPrimaryValue(columnsArr: any[]): void { public mapDefaultPrimaryValue(columnsArr: any[]): void {
// pk can be at the end // pk can be at the end
// //

3
packages/nocodb/src/lib/sqlMgr/code/models/xc/ModelXcMetaFactory.ts

@ -3,9 +3,10 @@ import ModelXcMetaSqlite from "./ModelXcMetaSqlite";
import ModelXcMetaPg from "./ModelXcMetaPg"; import ModelXcMetaPg from "./ModelXcMetaPg";
import ModelXcMetaMssql from "./ModelXcMetaMssql"; import ModelXcMetaMssql from "./ModelXcMetaMssql";
import ModelXcMetaOracle from "./ModelXcMetaOracle"; import ModelXcMetaOracle from "./ModelXcMetaOracle";
import BaseModelXcMeta from "./BaseModelXcMeta";
class ModelXcMetaFactory { class ModelXcMetaFactory {
public static create(connectionConfig, args) { public static create(connectionConfig, args):BaseModelXcMeta {
if (connectionConfig.client === "mysql2" || connectionConfig.client === "mysql") { if (connectionConfig.client === "mysql2" || connectionConfig.client === "mysql") {
return new ModelXcMetaMysql(args) return new ModelXcMetaMysql(args)
} else if (connectionConfig.client === "sqlite3") { } else if (connectionConfig.client === "sqlite3") {

2
packages/nocodb/src/lib/sqlMgr/code/routes/xc-ts/ExpressXcTsRoutes.ts

@ -327,7 +327,7 @@ async function(req, res){
} }
getObjectWithoutFunctions() { getObjectWithoutFunctions() {
return this.getObject().map(({functions, ...rest}) => rest) return this.getObject().map(({functions, ...rest}) => rest)
} }
} }

Loading…
Cancel
Save