Browse Source

feat: implement upgrader for table/view ordering, use tooldir from env

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/863/head
Pranav C 3 years ago
parent
commit
57bc9843aa
  1. 2
      packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue
  2. 2
      packages/nc-lib-gui/package.json
  3. 6
      packages/nocodb/package-lock.json
  4. 2
      packages/nocodb/package.json
  5. 8
      packages/nocodb/src/lib/noco/NcProjectBuilder.ts
  6. 6
      packages/nocodb/src/lib/noco/Noco.ts
  7. 23
      packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
  8. 48
      packages/nocodb/src/lib/noco/common/jobs/ncModelsOrderUpgrader.ts
  9. 4
      packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts
  10. 15
      packages/nocodb/src/lib/noco/meta/NcMetaIO.ts
  11. 10
      packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts
  12. 4
      packages/nocodb/src/lib/utils/NcConfigFactory.ts

2
packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue

@ -331,7 +331,7 @@ export default {
computed: { computed: {
selectAll: { selectAll: {
get() { get() {
return this.data.every(d => d.rowMeta && d.rowMeta.selected) return !!(this.data.length && this.data.every(d => d.rowMeta && d.rowMeta.selected))
}, },
set(v) { set(v) {
for (const d of this.data) { for (const d of this.data) {

2
packages/nc-lib-gui/package.json

@ -1,6 +1,6 @@
{ {
"name": "nc-lib-gui", "name": "nc-lib-gui",
"version": "0.83.5", "version": "0.83.117",
"description": "> TODO: description", "description": "> TODO: description",
"author": "“pranavxc” <pranavxc@gmail.com>", "author": "“pranavxc” <pranavxc@gmail.com>",
"homepage": "https://gitlab.com/xgenecloud-ts/xgenecloud-ts#readme", "homepage": "https://gitlab.com/xgenecloud-ts/xgenecloud-ts#readme",

6
packages/nocodb/package-lock.json generated

@ -12378,9 +12378,9 @@
} }
}, },
"nc-lib-gui": { "nc-lib-gui": {
"version": "0.83.5", "version": "0.83.117",
"resolved": "https://registry.npmjs.org/nc-lib-gui/-/nc-lib-gui-0.83.5.tgz", "resolved": "https://registry.npmjs.org/nc-lib-gui/-/nc-lib-gui-0.83.117.tgz",
"integrity": "sha512-BJV2ejigQ2DuMyto4BD7i/GIIBIijFDcMKOgYUqjuQYBBJSZ6KQbud5jZCOL+phs0+tvUmLK2afwAt0OE80QRg==", "integrity": "sha512-ktfZbr97tyrgSn6lnPQ4DwzkPzsCClI5MtmFofK630pE9XDJlfTfEZ+hyMBnB9GS3axukaO1XknnYPwW80FgPg==",
"requires": { "requires": {
"axios": "^0.19.2", "axios": "^0.19.2",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",

2
packages/nocodb/package.json

@ -147,7 +147,7 @@
"nanoid": "^3.1.20", "nanoid": "^3.1.20",
"nc-common": "0.0.6", "nc-common": "0.0.6",
"nc-help": "^0.2.18", "nc-help": "^0.2.18",
"nc-lib-gui": "0.83.5", "nc-lib-gui": "0.83.117",
"nc-plugin": "^0.1.1", "nc-plugin": "^0.1.1",
"ncp": "^2.0.0", "ncp": "^2.0.0",
"nodemailer": "^6.4.10", "nodemailer": "^6.4.10",

8
packages/nocodb/src/lib/noco/NcProjectBuilder.ts

@ -706,7 +706,7 @@ export default class NcProjectBuilder {
/* if migrator folder doesn't exist for project - call migratior init */ /* if migrator folder doesn't exist for project - call migratior init */
const migrationFolder = path.join( const migrationFolder = path.join(
this.config.toolDir, this.app.getToolDir(),
'nc', 'nc',
this.id, this.id,
connectionConfig.meta.dbAlias, connectionConfig.meta.dbAlias,
@ -714,7 +714,7 @@ export default class NcProjectBuilder {
); );
if (!fs.existsSync(migrationFolder)) { if (!fs.existsSync(migrationFolder)) {
await migrator.init({ await migrator.init({
folder: this.config?.toolDir, folder: this.app.getToolDir(),
env: this.appConfig.workingEnv, env: this.appConfig.workingEnv,
dbAlias: connectionConfig.meta.dbAlias dbAlias: connectionConfig.meta.dbAlias
}); });
@ -722,14 +722,14 @@ export default class NcProjectBuilder {
/* migrator : sync & up */ /* migrator : sync & up */
await migrator.sync({ await migrator.sync({
folder: this.config?.toolDir, folder: this.app.getToolDir(),
env: this.appConfig.workingEnv, env: this.appConfig.workingEnv,
dbAlias: connectionConfig.meta.dbAlias, dbAlias: connectionConfig.meta.dbAlias,
sqlClient sqlClient
}); });
await migrator.migrationsUp({ await migrator.migrationsUp({
folder: this.config?.toolDir, folder: this.app.getToolDir(),
env: this.appConfig.workingEnv, env: this.appConfig.workingEnv,
dbAlias: connectionConfig.meta.dbAlias, dbAlias: connectionConfig.meta.dbAlias,
migrationSteps: 99999, migrationSteps: 99999,

6
packages/nocodb/src/lib/noco/Noco.ts

@ -90,7 +90,7 @@ export default class Noco {
constructor() { constructor() {
process.env.PORT = process.env.PORT || '8080'; process.env.PORT = process.env.PORT || '8080';
// todo: move // todo: move
process.env.NC_VERSION = '0080000'; process.env.NC_VERSION = '0083006';
this.router = express.Router(); this.router = express.Router();
this.projectRouter = express.Router(); this.projectRouter = express.Router();
@ -274,6 +274,10 @@ export default class Noco {
return this.config; return this.config;
} }
public getToolDir(): string {
return this.getConfig()?.toolDir;
}
public addToContext(context: any) { public addToContext(context: any) {
this.requestContext = context; this.requestContext = context;
} }

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

@ -28,6 +28,7 @@ import { XcCron } from './XcCron';
import NcConnectionMgr from './NcConnectionMgr'; import NcConnectionMgr from './NcConnectionMgr';
import updateColumnNameInFormula from './helpers/updateColumnNameInFormula'; import updateColumnNameInFormula from './helpers/updateColumnNameInFormula';
import addErrorOnColumnDeleteInFormula from './helpers/addErrorOnColumnDeleteInFormula'; import addErrorOnColumnDeleteInFormula from './helpers/addErrorOnColumnDeleteInFormula';
import ncModelsOrderUpgrader from './jobs/ncModelsOrderUpgrader';
const log = debug('nc:api:base'); const log = debug('nc:api:base');
@ -1266,7 +1267,8 @@ export default abstract class BaseApiBuilder<T extends Noco>
const NC_VERSIONS = [ const NC_VERSIONS = [
{ name: '0009000', handler: null }, { name: '0009000', handler: null },
{ name: '0009044', handler: this.ncUpManyToMany.bind(this) } { name: '0009044', handler: this.ncUpManyToMany.bind(this) },
{ name: '0083006', handler: ncModelsOrderUpgrader }
]; ];
if (!(await this.xcMeta?.knex?.schema?.hasTable?.('nc_store'))) { if (!(await this.xcMeta?.knex?.schema?.hasTable?.('nc_store'))) {
return; return;
@ -1291,7 +1293,12 @@ export default abstract class BaseApiBuilder<T extends Noco>
configObj.version, configObj.version,
version.name version.name
); );
await version?.handler?.(); await version?.handler?.(<NcBuilderUpgraderCtx>{
xcMeta: this.xcMeta,
builder: this,
dbAlias: this.dbAlias,
projectId: this.projectId
});
// update version in meta after each upgrade // update version in meta after each upgrade
config.version = version.name; config.version = version.name;
@ -2404,7 +2411,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
return metas; return metas;
} }
protected async ncUpManyToMany(): Promise<any> { protected async ncUpManyToMany(_ctx: any): Promise<any> {
const models = await this.xcMeta.metaList( const models = await this.xcMeta.metaList(
this.projectId, this.projectId,
this.dbAlias, this.dbAlias,
@ -2933,6 +2940,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
public getMeta(tableName: string): any { public getMeta(tableName: string): any {
return this.metas?.[tableName]; return this.metas?.[tableName];
} }
protected async getOrderVal(): Promise<number> { protected async getOrderVal(): Promise<number> {
const order = const order =
( (
@ -2949,7 +2957,14 @@ export default abstract class BaseApiBuilder<T extends Noco>
} }
} }
export { IGNORE_TABLES }; interface NcBuilderUpgraderCtx {
xcMeta: NcMetaIO;
builder: BaseApiBuilder<any>;
projectId: string;
dbAlias: string;
}
export { IGNORE_TABLES, NcBuilderUpgraderCtx };
/** /**
* @copyright Copyright (c) 2021, Xgene Cloud Ltd * @copyright Copyright (c) 2021, Xgene Cloud Ltd

48
packages/nocodb/src/lib/noco/common/jobs/ncModelsOrderUpgrader.ts

@ -0,0 +1,48 @@
import { NcBuilderUpgraderCtx } from '../BaseApiBuilder';
export default async function(ctx: NcBuilderUpgraderCtx) {
const models = await ctx.xcMeta.metaList(
ctx.projectId,
ctx.dbAlias,
'nc_models',
{
xcCondition: {
_or: [{ type: { eq: 'table' } }, { type: { eq: 'view' } }]
}
}
);
let order = 0;
for (const model of models) {
await ctx.xcMeta.metaUpdate(
ctx.projectId,
ctx.dbAlias,
'nc_models',
{
order: ++order,
view_order: 1
},
model.id
);
const views = await ctx.xcMeta.metaList(
ctx.projectId,
ctx.dbAlias,
'nc_models',
{
condition: { parent_model_title: model.title }
}
);
let view_order = 1;
for (const view of views) {
await ctx.xcMeta.metaUpdate(
ctx.projectId,
ctx.dbAlias,
'nc_models',
{
view_order: ++view_order
},
view.id
);
}
}
}

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

@ -2830,8 +2830,8 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
await this.reInitializeGraphqlEndpoint(); await this.reInitializeGraphqlEndpoint();
} }
protected async ncUpManyToMany(): Promise<any> { protected async ncUpManyToMany(ctx: any): Promise<any> {
const metas = await super.ncUpManyToMany(); const metas = await super.ncUpManyToMany(ctx);
if (!metas) { if (!metas) {
return; return;

15
packages/nocodb/src/lib/noco/meta/NcMetaIO.ts

@ -214,16 +214,11 @@ export default abstract class NcMetaIO {
} }
type XcConditionStr = { type XcConditionStr = {
[key in [key in 'lt' | 'gt' | 'le' | 'ge' | 'like' | 'nlike' | 'eq' | 'in' | 'nin']:
| 'lt' | string
| 'gt' | number
| 'le' | boolean
| 'ge' | Date;
| 'like'
| 'nlike'
| 'eq'
| 'in'
| 'nin']: any;
}; };
interface XcCondition { interface XcCondition {

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

@ -2380,7 +2380,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
if (!this.config.try) { if (!this.config.try) {
this.log('generateSwaggerJson : Generating swagger.json'); this.log('generateSwaggerJson : Generating swagger.json');
const swaggerFilePath = path.join( const swaggerFilePath = path.join(
this.config.toolDir, this.app.getToolDir(),
'nc', 'nc',
this.projectId, this.projectId,
this.getDbAlias(), this.getDbAlias(),
@ -2435,7 +2435,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
glob glob
.sync( .sync(
path.join( path.join(
this.config.toolDir, this.app.getToolDir(),
'nc', 'nc',
this.projectId, this.projectId,
this.getDbAlias(), this.getDbAlias(),
@ -2506,7 +2506,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
/* load swagger JSON */ /* load swagger JSON */
const swaggerFilePath = path.join( const swaggerFilePath = path.join(
this.config.toolDir, this.app.getToolDir(),
'nc', 'nc',
this.projectId, this.projectId,
this.getDbAlias(), this.getDbAlias(),
@ -2624,8 +2624,8 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
); );
} }
protected async ncUpManyToMany(): Promise<any> { protected async ncUpManyToMany(ctx: any): Promise<any> {
const metas = await super.ncUpManyToMany(); const metas = await super.ncUpManyToMany(ctx);
if (!metas) { if (!metas) {
return; return;
} }

4
packages/nocodb/src/lib/utils/NcConfigFactory.ts

@ -53,13 +53,13 @@ export default class NcConfigFactory implements NcConfig {
config.port = +(process?.env?.PORT ?? 8080); config.port = +(process?.env?.PORT ?? 8080);
config.env = '_noco'; // process.env?.NODE_ENV || 'dev'; config.env = '_noco'; // process.env?.NODE_ENV || 'dev';
config.workingEnv = '_noco'; // process.env?.NODE_ENV || 'dev'; config.workingEnv = '_noco'; // process.env?.NODE_ENV || 'dev';
config.toolDir = this.getToolDir(); // config.toolDir = this.getToolDir();
config.projectType = config.projectType =
config?.envs?.[config.workingEnv]?.db?.[0]?.meta?.api?.type || 'rest'; config?.envs?.[config.workingEnv]?.db?.[0]?.meta?.api?.type || 'rest';
if (config.meta?.db?.connection?.filename) { if (config.meta?.db?.connection?.filename) {
config.meta.db.connection.filename = path.join( config.meta.db.connection.filename = path.join(
config.toolDir, this.getToolDir(),
config.meta.db.connection.filename config.meta.db.connection.filename
); );
} }

Loading…
Cancel
Save