Browse Source

feat: migration init

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
37b8b7b2c1
  1. BIN
      packages/nocodb-nest/noco.db
  2. 4046
      packages/nocodb-nest/package-lock.json
  3. 7
      packages/nocodb-nest/package.json
  4. 2
      packages/nocodb-nest/src/auth/auth.service.ts
  5. 29
      packages/nocodb-nest/src/connection/connection.ts
  6. 2
      packages/nocodb-nest/src/db/util/emit.ts
  7. 22
      packages/nocodb-nest/src/meta/meta.service.ts
  8. 6
      packages/nocodb-nest/src/users/users.service.ts

BIN
packages/nocodb-nest/noco.db

Binary file not shown.

4046
packages/nocodb-nest/package-lock.json generated

File diff suppressed because it is too large Load Diff

7
packages/nocodb-nest/package.json

@ -26,10 +26,15 @@
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^9.0.0",
"bcryptjs": "^2.4.3",
"boxen": "^5.0.0",
"colors": "^1.4.0",
"cors": "^2.8.5",
"dayjs": "^1.11.7",
"knex": "^2.4.2",
"emittery": "^0.7.1",
"knex": "2.2.0",
"mysql2": "^3.2.0",
"nanoid": "^3.1.20",
"nc-help": "^0.2.87",
"nocodb-sdk": "^0.106.0-beta.0",
"parse-database-url": "^0.3.0",
"passport-jwt": "^4.0.1",

2
packages/nocodb-nest/src/auth/auth.service.ts

@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import { OrgUserRoles } from 'nocodb-sdk'
import { UsersService } from '../users/users.service';
import { promisify } from 'util';
import bcrypt from 'bcryptjs';
import * as bcrypt from 'bcryptjs';
import { JwtService } from '@nestjs/jwt';
import { CreateUserDto } from './auth.controller';

29
packages/nocodb-nest/src/connection/connection.ts

@ -1,26 +1,21 @@
import { Global, Injectable } from '@nestjs/common'
import { Global, Injectable, OnModuleInit } from '@nestjs/common';
import * as knex from "knex";
import * as knex from 'knex';
import NcConfigFactory from '../utils/NcConfigFactory';
@Global()
@Injectable()
export class Connection {
private readonly knex: knex.Knex;
constructor() {
this.knex = knex.default({
client: "mysql2",
connection: {
host: "localhost",
user: "root",
password: "password",
database: "sakila"
}
});
}
export class Connection implements OnModuleInit {
private knex: knex.Knex;
private dbConfig: any;
get knexInstance(): knex.Knex {
return this.knex;
}
// init metadb connection
async onModuleInit(): Promise<void> {
this.dbConfig = await NcConfigFactory.make();
this.knex = knex.default({ ...this.dbConfig.meta.db, useNullAsDefault: true });
}
}

2
packages/nocodb-nest/src/db/util/emit.ts

@ -1,4 +1,4 @@
import Emittery from 'emittery';
import * as Emittery from 'emittery';
let emitSingleton = null;

22
packages/nocodb-nest/src/meta/meta.service.ts

@ -1,6 +1,6 @@
import { Global, Injectable } from '@nestjs/common'
import XcMigrationSource from './migrations/XcMigrationSource'
import XcMigrationSourcev2 from './migrations/XcMigrationSourcev2'
import { Global, Inject, Injectable, OnApplicationBootstrap, OnModuleInit } from '@nestjs/common'
import XcMigrationSource from './migrations/XcMigrationSource';
import XcMigrationSourcev2 from './migrations/XcMigrationSourcev2';
import { Connection } from '../connection/connection';
import { customAlphabet } from 'nanoid';
@ -51,7 +51,6 @@ export enum MetaTable {
STORE = 'nc_store',
}
export const orderedMetaTables = [
MetaTable.MODEL_ROLE_VISIBILITY,
MetaTable.PLUGIN,
@ -171,13 +170,11 @@ const nanoidv2 = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 14);
@Global()
@Injectable()
export class MetaService {
constructor(private connection: Connection) {
}
export class MetaService implements OnApplicationBootstrap {
constructor(private connection: Connection) {}
public async metaInit(): Promise<boolean> {
await this.connection.knexInstance.migrate.latest({
migrationSource: new XcMigrationSource(),
tableName: 'xc_knex_migrations',
@ -238,7 +235,7 @@ export class MetaService {
base_id: string,
target: string,
data: any,
ignoreIdGeneration?: boolean
ignoreIdGeneration?: boolean,
): Promise<any> {
const id = data?.id || this.genNanoid(target);
const insertObj = {
@ -254,7 +251,6 @@ export class MetaService {
return insertObj;
}
private genNanoid(target: string) {
let prefix;
switch (target) {
@ -347,4 +343,8 @@ export class MetaService {
return `${prefix}${nanoidv2()}`;
}
async onApplicationBootstrap(): Promise<void> {
await this.metaInit();
}
}

6
packages/nocodb-nest/src/users/users.service.ts

@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { MetaService } from '../meta/meta.service';
import { MetaService, MetaTable } from '../meta/meta.service'
@Injectable()
export class UsersService {
@ -8,7 +8,7 @@ export class UsersService {
}
async findOne(email: string) {
const user = await this.metaService.metaGet(null, null, 'users', { email });
const user = await this.metaService.metaGet(null, null, MetaTable.USERS, { email });
return user;
@ -16,6 +16,6 @@ export class UsersService {
}
async insert(param: { token_version: string; firstname: any; password: any; salt: any; email_verification_token: any; roles: string; email: string; lastname: any }) {
return this.metaService.metaInsert2(null, null, 'users', param)
return this.metaService.metaInsert2(null, null, MetaTable.USERS, param)
}
}

Loading…
Cancel
Save