Browse Source

refactor: rename metatables and remove unused tables

Signed-off-by: Pranav C <pranavxc@gmail.com>
refactor/rename-meta-tables
Pranav C 2 years ago
parent
commit
173d6bfef4
  1. 3
      packages/nocodb/package.json
  2. 9
      packages/nocodb/src/lib/Noco.ts
  3. 6
      packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts
  4. 110
      packages/nocodb/src/lib/meta/NcMetaIOImpl.ts
  5. 11
      packages/nocodb/src/lib/meta/NcMetaMgr.ts
  6. 2
      packages/nocodb/src/lib/meta/api/sync/helpers/EntityMap.ts
  7. 6
      packages/nocodb/src/lib/meta/api/userApi/initAdminFromEnv.ts
  8. 6
      packages/nocodb/src/lib/meta/api/userApi/userApis.ts
  9. 12
      packages/nocodb/src/lib/meta/api/utilApis.ts
  10. 9
      packages/nocodb/src/lib/migrations/XcMigrationSource.ts
  11. 10
      packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts
  12. 57
      packages/nocodb/src/lib/migrations/v1/nc_012_rename_table.ts
  13. 26
      packages/nocodb/src/lib/migrations/v1/nc_013_delete_tables.ts
  14. 5
      packages/nocodb/src/lib/migrations/v2/nc_011.ts
  15. 2
      packages/nocodb/src/lib/migrations/v2/nc_012_alter_column_data_types.ts
  16. 2
      packages/nocodb/src/lib/migrations/v2/nc_013_sync_source.ts
  17. 2
      packages/nocodb/src/lib/migrations/v2/nc_014_alter_column_data_types.ts
  18. 2
      packages/nocodb/src/lib/migrations/v2/nc_015_add_meta_col_in_column_table.ts
  19. 2
      packages/nocodb/src/lib/migrations/v2/nc_016_alter_hooklog_payload_types.ts
  20. 5
      packages/nocodb/src/lib/migrations/v2/nc_017_add_user_token_version_column.ts
  21. 2
      packages/nocodb/src/lib/migrations/v2/nc_018_add_meta_in_view.ts
  22. 2
      packages/nocodb/src/lib/migrations/v2/nc_019_add_meta_in_meta_tables.ts
  23. 2
      packages/nocodb/src/lib/migrations/v2/nc_020_kanban_view.ts
  24. 2
      packages/nocodb/src/lib/migrations/v2/nc_021_add_fields_in_token.ts
  25. 2
      packages/nocodb/src/lib/migrations/v2/nc_022_qr_code_column_type.ts
  26. 200
      packages/nocodb/src/lib/migrations/v2/nc_023_rename_table.ts
  27. 23
      packages/nocodb/src/lib/migrations/v2/nc_024_delete_table.ts
  28. 40
      packages/nocodb/src/lib/models/ApiToken.ts
  29. 14
      packages/nocodb/src/lib/models/Base.ts
  30. 40
      packages/nocodb/src/lib/models/Column.ts
  31. 10
      packages/nocodb/src/lib/models/FormViewColumn.ts
  32. 8
      packages/nocodb/src/lib/models/GalleryViewColumn.ts
  33. 10
      packages/nocodb/src/lib/models/GridViewColumn.ts
  34. 10
      packages/nocodb/src/lib/models/Hook.ts
  35. 4
      packages/nocodb/src/lib/models/HookLog.ts
  36. 27
      packages/nocodb/src/lib/models/KanbanViewColumn.ts
  37. 4
      packages/nocodb/src/lib/models/LinkToAnotherRecordColumn.ts
  38. 42
      packages/nocodb/src/lib/models/Model.ts
  39. 42
      packages/nocodb/src/lib/models/ProjectUser.ts
  40. 8
      packages/nocodb/src/lib/models/SelectOption.ts
  41. 6
      packages/nocodb/src/lib/models/SyncLogs.ts
  42. 42
      packages/nocodb/src/lib/models/User.ts
  43. 44
      packages/nocodb/src/lib/models/View.ts
  44. 2
      packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts
  45. 2
      packages/nocodb/src/lib/plugins/gcs/Gcs.ts
  46. 2
      packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts
  47. 2
      packages/nocodb/src/lib/plugins/mino/Minio.ts
  48. 2
      packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts
  49. 2
      packages/nocodb/src/lib/plugins/s3/S3.ts
  50. 2
      packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts
  51. 2
      packages/nocodb/src/lib/plugins/spaces/Spaces.ts
  52. 2
      packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts
  53. 2
      packages/nocodb/src/lib/plugins/vultr/Vultr.ts
  54. 17
      packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts
  55. 9
      packages/nocodb/src/lib/utils/common/jobs/ncModelsOrderUpgrader.ts
  56. 5
      packages/nocodb/src/lib/utils/common/jobs/ncParentModelTitleUpgrader.ts
  57. 11
      packages/nocodb/src/lib/utils/common/jobs/ncRemoveDuplicatedRelationRows.ts
  58. 4
      packages/nocodb/src/lib/utils/getInstance.ts
  59. 85
      packages/nocodb/src/lib/utils/globals.ts
  60. 214
      packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts
  61. 83
      packages/nocodb/src/lib/v1-legacy/gql/GqlApiBuilder.ts
  62. 14
      packages/nocodb/src/lib/v1-legacy/plugins/NcPluginMgr.ts
  63. 116
      packages/nocodb/src/lib/v1-legacy/rest/RestApiBuilder.ts
  64. 77
      packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrl.ts
  65. 11
      packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrlEE.ts
  66. 23
      packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts
  67. 2
      packages/nocodb/src/lib/version-upgrader/handlers/nc_0011043_project_env_upgrader.ts
  68. 2
      packages/nocodb/src/lib/version-upgrader/handlers/nc_0011045_project_env_upgrader.ts
  69. 80
      packages/nocodb/src/lib/version-upgrader/handlers/nc_0090000_project_v2_upgrader.ts
  70. 6
      packages/nocodb/src/lib/version-upgrader/handlers/nc_0098004_data_types_upgrader.ts
  71. 12
      packages/nocodb/src/lib/version-upgrader/handlers/nc_0098005_project_roles_upgrader.ts

3
packages/nocodb/package.json

@ -79,9 +79,6 @@
"fast-levenshtein": "^2.0.6",
"fs-extra": "^9.0.1",
"glob": "^7.1.6",
"graphql": "^15.3.0",
"graphql-depth-limit": "^1.1.0",
"graphql-type-json": "^0.3.2",
"handlebars": "^4.7.6",
"import-fresh": "^3.2.1",
"inflection": "^1.12.0",

9
packages/nocodb/src/lib/Noco.ts

@ -17,6 +17,7 @@ import { v4 as uuidv4 } from 'uuid';
import { NcConfig } from '../interface/config';
import Migrator from './db/sql-migrator/lib/KnexMigrator';
import { MetaTable } from './utils/globals'
import NcConfigFactory from './utils/NcConfigFactory';
import { Tele } from 'nc-help';
@ -498,12 +499,12 @@ export default class Noco {
if (this.config?.auth?.jwt) {
if (!this.config.auth.jwt.secret) {
let secret = (
await Noco._ncMeta.metaGet('', '', 'nc_store', {
await Noco._ncMeta.metaGet('', '', MetaTable.STORE, {
key: 'nc_auth_jwt_secret',
})
)?.value;
if (!secret) {
await Noco._ncMeta.metaInsert('', '', 'nc_store', {
await Noco._ncMeta.metaInsert('', '', MetaTable.STORE, {
key: 'nc_auth_jwt_secret',
value: (secret = uuidv4()),
});
@ -518,12 +519,12 @@ export default class Noco {
}
}
let serverId = (
await Noco._ncMeta.metaGet('', '', 'nc_store', {
await Noco._ncMeta.metaGet('', '', MetaTable.STORE, {
key: 'nc_server_id',
})
)?.value;
if (!serverId) {
await Noco._ncMeta.metaInsert('', '', 'nc_store', {
await Noco._ncMeta.metaInsert('', '', MetaTable.STORE, {
key: 'nc_server_id',
value: (serverId = Tele.id),
});

6
packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts

@ -2004,7 +2004,7 @@ class SqliteClient extends KnexClient {
if (change === 2) {
const suffix = nanoid();
let backupOldColumnQuery = this.genQuery(
const backupOldColumnQuery = this.genQuery(
`ALTER TABLE ?? RENAME COLUMN ?? TO ??;`,
[t, o.cn, `${o.cno}_nc_${suffix}`],
shouldSanitize
@ -2029,13 +2029,13 @@ class SqliteClient extends KnexClient {
shouldSanitize
);
let updateNewColumnQuery = this.genQuery(
const updateNewColumnQuery = this.genQuery(
`UPDATE ?? SET ?? = ??;`,
[t, n.cn, `${o.cno}_nc_${suffix}`],
shouldSanitize
);
let dropOldColumnQuery = this.genQuery(
const dropOldColumnQuery = this.genQuery(
`ALTER TABLE ?? DROP COLUMN ??;`,
[t, `${o.cno}_nc_${suffix}`],
shouldSanitize

110
packages/nocodb/src/lib/meta/NcMetaIOImpl.ts

@ -8,7 +8,7 @@ import XcMigrationSource from '../migrations/XcMigrationSource';
import NcMetaIO, { META_TABLES } from './NcMetaIO';
import NcConnectionMgr from '../utils/common/NcConnectionMgr';
import { MetaTable } from '../utils/globals';
import { MetaTable, MetaTableV1 } from '../utils/globals';
import XcMigrationSourcev2 from '../migrations/XcMigrationSourcev2';
// import { nanoid } from 'nanoid';
@ -527,7 +527,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
).toString(),
};
// todo: check project name used or not
await this.knexConnection('nc_projects').insert({
await this.knexConnection(MetaTableV1.PROJECTS).insert({
...project,
created_at: this.knexConnection?.fn?.now(),
updated_at: this.knexConnection?.fn?.now(),
@ -555,7 +555,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
).toString(),
};
// todo: check project name used or not
await this.knexConnection('nc_projects').update(project).where({
await this.knexConnection(MetaTableV1.PROJECTS).update(project).where({
id: projectId,
});
} catch (e) {
@ -564,38 +564,42 @@ export default class NcMetaIOImpl extends NcMetaIO {
}
public async projectList(): Promise<any[]> {
return (await this.knexConnection('nc_projects').select()).map((p) => {
p.config = CryptoJS.AES.decrypt(
p.config,
this.config?.auth?.jwt?.secret
).toString(CryptoJS.enc.Utf8);
return p;
});
return (await this.knexConnection(MetaTableV1.PROJECTS).select()).map(
(p) => {
p.config = CryptoJS.AES.decrypt(
p.config,
this.config?.auth?.jwt?.secret
).toString(CryptoJS.enc.Utf8);
return p;
}
);
}
public async userProjectList(userId: any): Promise<any[]> {
return (
await this.knexConnection('nc_projects')
await this.knexConnection(MetaTableV1.PROJECTS)
.leftJoin(
this.knexConnection('nc_projects_users')
.where(`nc_projects_users.user_id`, userId)
this.knexConnection(MetaTableV1.PROJECTS_USERS)
.where(`${MetaTableV1.PROJECTS_USERS}.user_id`, userId)
.as('user'),
'user.project_id',
'nc_projects.id'
`${MetaTableV1.PROJECTS}.id`
)
.select('nc_projects.*')
.select(`${MetaTableV1.PROJECTS}.*`)
.select('user.user_id')
.select(
this.knexConnection('xc_users')
.select('xc_users.email')
.innerJoin(
'nc_projects_users',
'nc_projects_users.user_id',
MetaTableV1.PROJECTS_USERS,
`${MetaTableV1.PROJECTS_USERS}.user_id`,
'=',
'xc_users.id'
)
.whereRaw('nc_projects.id = nc_projects_users.project_id')
.where('nc_projects_users.roles', 'like', '%owner%')
.whereRaw(
`${MetaTableV1.PROJECTS}.id = ${MetaTableV1.PROJECTS_USERS}.project_id`
)
.where(`${MetaTableV1.PROJECTS_USERS}.roles`, 'like', '%owner%')
.first()
.as('owner')
)
@ -603,19 +607,25 @@ export default class NcMetaIOImpl extends NcMetaIO {
this.knexConnection('xc_users')
.count('xc_users.id')
.innerJoin(
'nc_projects_users',
'nc_projects_users.user_id',
MetaTableV1.PROJECTS_USERS,
`${MetaTableV1.PROJECTS_USERS}.user_id`,
'=',
'xc_users.id'
)
.where((qb) => {
qb.where('nc_projects_users.roles', 'like', '%creator%').orWhere(
'nc_projects_users.roles',
qb.where(
`${MetaTableV1.PROJECTS_USERS}.roles`,
'like',
'%creator%'
).orWhere(
`${MetaTableV1.PROJECTS_USERS}.roles`,
'like',
'%owner%'
);
})
.whereRaw('nc_projects.id = nc_projects_users.project_id')
.whereRaw(
`nc_projects.id = ${MetaTableV1.PROJECTS_USERS}.project_id`
)
.andWhere('xc_users.id', userId)
.first()
.as('is_creator')
@ -634,7 +644,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
projectId: string,
userId: any
): Promise<boolean> {
return !!(await this.knexConnection('nc_projects_users')
return !!(await this.knexConnection(MetaTableV1.PROJECTS_USERS)
.where({
project_id: projectId,
user_id: userId,
@ -643,7 +653,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
}
public async projectGet(projectName: string, encrypt?): Promise<any> {
const project = await this.knexConnection('nc_projects')
const project = await this.knexConnection(MetaTableV1.PROJECTS)
.where({
title: projectName,
})
@ -659,7 +669,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
}
public async projectGetById(projectId: string, encrypt?): Promise<any> {
const project = await this.knexConnection('nc_projects')
const project = await this.knexConnection(MetaTableV1.PROJECTS)
.where({
id: projectId,
})
@ -674,7 +684,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
}
public projectDelete(title: string): Promise<any> {
return this.knexConnection('nc_projects')
return this.knexConnection(MetaTableV1.PROJECTS)
.where({
title,
})
@ -682,7 +692,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
}
public projectDeleteById(id: string): Promise<any> {
return this.knexConnection('nc_projects')
return this.knexConnection(MetaTableV1.PROJECTS)
.where({
id,
})
@ -693,7 +703,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
projectId: string,
status: string
): Promise<any> {
return this.knexConnection('nc_projects')
return this.knexConnection(MetaTableV1.PROJECTS)
.update({
status,
})
@ -708,7 +718,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
roles: string
): Promise<any> {
if (
await this.knexConnection('nc_projects_users')
await this.knexConnection(MetaTableV1.PROJECTS_USERS)
.where({
user_id: userId,
project_id: projectId,
@ -717,7 +727,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
) {
return {};
}
return this.knexConnection('nc_projects_users').insert({
return this.knexConnection(MetaTableV1.PROJECTS_USERS).insert({
user_id: userId,
project_id: projectId,
roles,
@ -725,7 +735,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
}
public projectRemoveUser(projectId: string, userId: any): Promise<any> {
return this.knexConnection('nc_projects_users')
return this.knexConnection(MetaTableV1.PROJECTS_USERS)
.where({
user_id: userId,
project_id: projectId,
@ -785,19 +795,19 @@ export default class NcMetaIOImpl extends NcMetaIO {
case MetaTable.PROJECT:
prefix = 'p_';
break;
case MetaTable.BASES:
case MetaTable.BASE:
prefix = 'ds_';
break;
case MetaTable.MODELS:
case MetaTable.MODEL:
prefix = 'md_';
break;
case MetaTable.COLUMNS:
case MetaTable.COLUMN:
prefix = 'cl_';
break;
case MetaTable.COL_RELATIONS:
case MetaTable.COL_RELATION:
prefix = 'ln_';
break;
case MetaTable.COL_SELECT_OPTIONS:
case MetaTable.COL_SELECT_OPTION:
prefix = 'sl_';
break;
case MetaTable.COL_LOOKUP:
@ -818,46 +828,38 @@ export default class NcMetaIOImpl extends NcMetaIO {
case MetaTable.SHARED_VIEWS:
prefix = 'sv_';
break;
case MetaTable.ACL:
prefix = 'ac_';
break;
case MetaTable.FORM_VIEW:
prefix = 'fv_';
break;
case MetaTable.FORM_VIEW_COLUMNS:
case MetaTable.FORM_VIEW_COLUMN:
prefix = 'fvc_';
break;
case MetaTable.GALLERY_VIEW:
prefix = 'gv_';
break;
case MetaTable.GALLERY_VIEW_COLUMNS:
case MetaTable.GALLERY_VIEW_COLUMN:
prefix = 'gvc_';
break;
case MetaTable.KANBAN_VIEW:
prefix = 'kv_';
break;
case MetaTable.KANBAN_VIEW_COLUMNS:
case MetaTable.KANBAN_VIEW_COLUMN:
prefix = 'kvc_';
break;
case MetaTable.USERS:
case MetaTable.USER:
prefix = 'us_';
break;
case MetaTable.ORGS:
prefix = 'org_';
break;
case MetaTable.TEAMS:
prefix = 'tm_';
break;
case MetaTable.VIEWS:
case MetaTable.VIEW:
prefix = 'vw_';
break;
case MetaTable.HOOKS:
case MetaTable.HOOK:
prefix = 'hk_';
break;
case MetaTable.AUDIT:
prefix = 'adt_';
break;
case MetaTable.API_TOKENS:
case MetaTable.API_TOKEN:
prefix = 'tkn_';
break;
default:

11
packages/nocodb/src/lib/meta/NcMetaMgr.ts

@ -24,6 +24,7 @@ import ProjectMgr from '../db/sql-mgr/ProjectMgr';
import ExpressXcTsRoutes from '../db/sql-mgr/code/routes/xc-ts/ExpressXcTsRoutes';
import ExpressXcTsRoutesBt from '../db/sql-mgr/code/routes/xc-ts/ExpressXcTsRoutesBt';
import ExpressXcTsRoutesHm from '../db/sql-mgr/code/routes/xc-ts/ExpressXcTsRoutesHm';
import { MetaTable } from '../utils/globals';
import NcHelp from '../utils/NcHelp';
import mimetypes, { mimeIcons } from '../utils/mimeTypes';
import { packageVersion } from '../utils/packageVersion';
@ -2016,7 +2017,7 @@ export default class NcMetaMgr {
return this.xcMeta.metaUpdate(
args.project_id,
'',
'nc_store',
MetaTable.STORE,
{
value: JSON.stringify(args.args),
},
@ -2027,7 +2028,7 @@ export default class NcMetaMgr {
}
protected async xcDebugGet(_args) {
return this.xcMeta.metaGet('', '', 'nc_store', {
return this.xcMeta.metaGet('', '', MetaTable.STORE, {
key: 'NC_DEBUG',
});
}
@ -5156,7 +5157,7 @@ export default class NcMetaMgr {
}
protected async xcApiTokenList(_args): Promise<any> {
return this.xcMeta.metaList(null, null, 'nc_api_tokens');
return this.xcMeta.metaList(null, null, MetaTable.API_TOKEN);
}
protected async xcPluginDemoDefaults(_args): Promise<any> {
@ -5259,7 +5260,7 @@ export default class NcMetaMgr {
protected async xcApiTokenCreate(args): Promise<any> {
const token = nanoid(40);
await this.xcMeta.metaInsert(null, null, 'nc_api_tokens', {
await this.xcMeta.metaInsert(null, null, MetaTable.API_TOKEN, {
description: args.args.description,
token,
});
@ -5281,7 +5282,7 @@ export default class NcMetaMgr {
const res = await this.xcMeta.metaDelete(
null,
null,
'nc_api_tokens',
MetaTable.API_TOKEN,
args.args.id
);
await RestAuthCtrl.instance.loadLatestApiTokens();

2
packages/nocodb/src/lib/meta/api/sync/helpers/EntityMap.ts

@ -180,7 +180,7 @@ class DBStream extends Readable {
}
_read() {
let stream = this;
const stream = this;
this.stmt.get(function (err, result) {
if (err) {
stream.emit('error', err);

6
packages/nocodb/src/lib/meta/api/userApi/initAdminFromEnv.ts

@ -92,7 +92,7 @@ export default async function initAdminFromEnv(_ncMeta = Noco.ncMeta) {
salt
);
const email_verification_token = uuidv4();
const superUser = await ncMeta.metaGet2(null, null, MetaTable.USERS, {
const superUser = await ncMeta.metaGet2(null, null, MetaTable.USER, {
roles: 'user,super',
});
@ -157,7 +157,7 @@ export default async function initAdminFromEnv(_ncMeta = Noco.ncMeta) {
const existingUserProjects = await ncMeta.metaList2(
null,
null,
MetaTable.PROJECT_USERS,
MetaTable.PROJECT_USER,
{
condition: { fk_user_id: existingUserWithNewEmail.id },
}
@ -206,7 +206,7 @@ export default async function initAdminFromEnv(_ncMeta = Noco.ncMeta) {
await ncMeta.metaDelete(
null,
null,
MetaTable.USERS,
MetaTable.USER,
existingUserWithNewEmail.id
);

6
packages/nocodb/src/lib/meta/api/userApi/userApis.ts

@ -366,7 +366,7 @@ async function passwordForgot(req: Request<any, any>, res): Promise<any> {
async function tokenValidate(req, res): Promise<any> {
const token = req.params.tokenId;
const user = await Noco.ncMeta.metaGet(null, null, MetaTable.USERS, {
const user = await Noco.ncMeta.metaGet(null, null, MetaTable.USER, {
reset_password_token: token,
});
@ -382,7 +382,7 @@ async function tokenValidate(req, res): Promise<any> {
async function passwordReset(req, res): Promise<any> {
const token = req.params.tokenId;
const user = await Noco.ncMeta.metaGet(null, null, MetaTable.USERS, {
const user = await Noco.ncMeta.metaGet(null, null, MetaTable.USER, {
reset_password_token: token,
});
@ -428,7 +428,7 @@ async function passwordReset(req, res): Promise<any> {
async function emailVerification(req, res): Promise<any> {
const token = req.params.tokenId;
const user = await Noco.ncMeta.metaGet(null, null, MetaTable.USERS, {
const user = await Noco.ncMeta.metaGet(null, null, MetaTable.USER, {
email_verification_token: token,
});

12
packages/nocodb/src/lib/meta/api/utilApis.ts

@ -217,7 +217,7 @@ interface AllMeta {
export async function aggregatedMetaInfo(_req: Request, res: Response) {
const [projects, userCount] = await Promise.all([
Project.list({}),
Noco.ncMeta.metaCount(null, null, MetaTable.USERS),
Noco.ncMeta.metaCount(null, null, MetaTable.USER),
]);
const result: AllMeta = {
@ -244,13 +244,13 @@ export async function aggregatedMetaInfo(_req: Request, res: Response) {
] = extractResultOrNull(
await Promise.allSettled([
// db tables count
Noco.ncMeta.metaCount(project.id, null, MetaTable.MODELS, {
Noco.ncMeta.metaCount(project.id, null, MetaTable.MODEL, {
condition: {
type: 'table',
},
}),
// db views count
Noco.ncMeta.metaCount(project.id, null, MetaTable.MODELS, {
Noco.ncMeta.metaCount(project.id, null, MetaTable.MODEL, {
condition: {
type: 'view',
},
@ -260,7 +260,7 @@ export async function aggregatedMetaInfo(_req: Request, res: Response) {
const views = await Noco.ncMeta.metaList2(
project.id,
null,
MetaTable.VIEWS
MetaTable.VIEW
);
// grid, form, gallery, kanban and shared count
return views.reduce<ViewCount>(
@ -308,7 +308,7 @@ export async function aggregatedMetaInfo(_req: Request, res: Response) {
);
})(),
// webhooks count
Noco.ncMeta.metaCount(project.id, null, MetaTable.HOOKS),
Noco.ncMeta.metaCount(project.id, null, MetaTable.HOOK),
// filters count
Noco.ncMeta.metaCount(project.id, null, MetaTable.FILTER_EXP),
// sorts count
@ -326,7 +326,7 @@ export async function aggregatedMetaInfo(_req: Request, res: Response) {
);
}),
// project users count
Noco.ncMeta.metaCount(null, null, MetaTable.PROJECT_USERS, {
Noco.ncMeta.metaCount(null, null, MetaTable.PROJECT_USER, {
condition: {
project_id: project.id,
},

9
packages/nocodb/src/lib/migrations/XcMigrationSource.ts

@ -9,6 +9,8 @@ import * as nc_008_add_nc_shared_bases from './v1/nc_008_add_nc_shared_bases';
import * as nc_009_add_model_order from './v1/nc_009_add_model_order';
import * as nc_010_add_parent_title_column from './v1/nc_010_add_parent_title_column';
import * as nc_011_remove_old_ses_plugin from './v1/nc_011_remove_old_ses_plugin';
import * as nc_012_rename_table from './v1/nc_012_rename_table';
import * as nc_013_delete_tables from './v1/nc_013_delete_tables';
// Create a custom migration source class
export default class XcMigrationSource {
@ -29,6 +31,8 @@ export default class XcMigrationSource {
'nc_009_add_model_order',
'nc_010_add_parent_title_column',
'nc_011_remove_old_ses_plugin',
'nc_012_rename_table',
'nc_013_delete_tables',
]);
}
@ -60,6 +64,11 @@ export default class XcMigrationSource {
return nc_010_add_parent_title_column;
case 'nc_011_remove_old_ses_plugin':
return nc_011_remove_old_ses_plugin;
case 'nc_012_rename_table':
return nc_012_rename_table;
case 'nc_013_delete_tables':
return nc_013_delete_tables;
}
}
}

10
packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts

@ -11,6 +11,8 @@ import * as nc_020_kanban_view from './v2/nc_020_kanban_view';
import * as nc_021_add_fields_in_token from './v2/nc_021_add_fields_in_token';
import * as nc_022_qr_code_column_type from './v2/nc_022_qr_code_column_type';
import * as nc_023_multiple_source from './v2/nc_023_multiple_source';
import * as nc_023_rename_table from './v2/nc_023_rename_table';
import * as nc_024_delete_table from './v2/nc_024_delete_table';
// Create a custom migration source class
export default class XcMigrationSourcev2 {
@ -32,7 +34,9 @@ export default class XcMigrationSourcev2 {
'nc_020_kanban_view',
'nc_021_add_fields_in_token',
'nc_022_qr_code_column_type',
'nc_023_multiple_source'
'nc_023_multiple_source',
'nc_023_rename_table',
'nc_024_delete_table',
]);
}
@ -68,6 +72,10 @@ export default class XcMigrationSourcev2 {
return nc_022_qr_code_column_type;
case 'nc_023_multiple_source':
return nc_023_multiple_source;
case 'nc_023_rename_table':
return nc_023_rename_table;
case 'nc_024_delete_table':
return nc_024_delete_table;
}
}
}

57
packages/nocodb/src/lib/migrations/v1/nc_012_rename_table.ts

@ -0,0 +1,57 @@
import { Knex } from 'knex';
/***
* Rename v2 meta tables
*
* "nc_acl" => "z_acl"
* "nc_audit" => "z_audit"
* "nc_disabled_models_for_role" => "z_disabled_models_for_role"
* "nc_hooks" => "z_hooks"
* "nc_migrations" => "z_migrations"
* "nc_models" => "z_models"
* "nc_plugins" => "z_plugins"
* "nc_projects" => "z_projects"
* "nc_projects_users" => "z_projects_users"
* "nc_relations" => "z_relations"
* "nc_shared_bases" => "z_shared_bases"
* "nc_shared_views" => "z_shared_views"
*
*****/
const up = async (knex: Knex) => {
await knex.schema.renameTable('nc_acl', 'z_acl');
await knex.schema.renameTable('nc_audit', 'z_audit');
await knex.schema.renameTable(
'nc_disabled_models_for_role',
'z_disabled_models_for_role'
);
await knex.schema.renameTable('nc_hooks', 'z_hooks');
await knex.schema.renameTable('nc_migrations', 'z_migrations');
await knex.schema.renameTable('nc_models', 'z_models');
await knex.schema.renameTable('nc_plugins', 'z_plugins');
await knex.schema.renameTable('nc_projects', 'z_projects');
await knex.schema.renameTable('nc_projects_users', 'z_projects_users');
await knex.schema.renameTable('nc_relations', 'z_relations');
await knex.schema.renameTable('nc_shared_bases', 'z_shared_bases');
await knex.schema.renameTable('nc_shared_views', 'z_shared_views');
};
const down = async (knex: Knex) => {
await knex.schema.renameTable('z_acl', 'nc_acl');
await knex.schema.renameTable('z_audit', 'nc_audit');
await knex.schema.renameTable(
'z_disabled_models_for_role',
'nc_disabled_models_for_role'
);
await knex.schema.renameTable('z_hooks', 'nc_hooks');
await knex.schema.renameTable('z_migrations', 'nc_migrations');
await knex.schema.renameTable('z_models', 'nc_models');
await knex.schema.renameTable('z_plugins', 'nc_plugins');
await knex.schema.renameTable('z_projects', 'nc_projects');
await knex.schema.renameTable('z_projects_users', 'nc_projects_users');
await knex.schema.renameTable('z_relations', 'nc_relations');
await knex.schema.renameTable('z_shared_bases', 'nc_shared_bases');
await knex.schema.renameTable('z_shared_views', 'nc_shared_views');
};
export { up, down };

26
packages/nocodb/src/lib/migrations/v1/nc_013_delete_tables.ts

@ -0,0 +1,26 @@
import { Knex } from 'knex';
/***
* Delete unused v2 meta tables
*
* "nc_cron"
* "nc_loaders"
* "nc_resolvers"
* "nc_roles"
* "nc_routes"
* "nc_rpc"
*
*****/
const up = async (knex: Knex) => {
await knex.schema.dropTableIfExists('nc_cron');
await knex.schema.dropTableIfExists('nc_roles');
await knex.schema.dropTableIfExists('nc_routes');
await knex.schema.dropTableIfExists('nc_rpc');
};
const down = async (_knex: Knex) => {
// todo: add down migration
};
export { up, down };

5
packages/nocodb/src/lib/migrations/v2/nc_011.ts

@ -1,4 +1,7 @@
import { MetaTable, orderedMetaTables } from '../../utils/globals';
import {
MetaTableOld as MetaTable,
orderedMetaTables,
} from '../../utils/globals';
// import googleAuth from '../plugins/googleAuth';
// import ses from '../plugins/ses';
// import cache from '../plugins/cache';

2
packages/nocodb/src/lib/migrations/v2/nc_012_alter_column_data_types.ts

@ -1,5 +1,5 @@
import { Knex } from 'knex';
import { MetaTable } from '../../utils/globals';
import { MetaTableOld as MetaTable } from '../../utils/globals';
const up = async (knex: Knex) => {
if (knex.client.config.client !== 'sqlite3') {

2
packages/nocodb/src/lib/migrations/v2/nc_013_sync_source.ts

@ -1,5 +1,5 @@
import { Knex } from 'knex';
import { MetaTable } from '../../utils/globals';
import { MetaTableOld as MetaTable } from '../../utils/globals';
const up = async (knex: Knex) => {
await knex.schema.createTable(MetaTable.SYNC_SOURCE, (table) => {

2
packages/nocodb/src/lib/migrations/v2/nc_014_alter_column_data_types.ts

@ -1,5 +1,5 @@
import { Knex } from 'knex';
import { MetaTable } from '../../utils/globals';
import { MetaTableOld as MetaTable } from '../../utils/globals';
const up = async (knex: Knex) => {
if (knex.client.config.client !== 'sqlite3') {

2
packages/nocodb/src/lib/migrations/v2/nc_015_add_meta_col_in_column_table.ts

@ -1,5 +1,5 @@
import { Knex } from 'knex';
import { MetaTable } from '../../utils/globals';
import { MetaTableOld as MetaTable } from '../../utils/globals';
const up = async (knex: Knex) => {
await knex.schema.alterTable(MetaTable.COLUMNS, (table) => {

2
packages/nocodb/src/lib/migrations/v2/nc_016_alter_hooklog_payload_types.ts

@ -1,5 +1,5 @@
import { Knex } from 'knex';
import { MetaTable } from '../../utils/globals';
import { MetaTableOld as MetaTable } from '../../utils/globals';
const up = async (knex: Knex) => {
if (knex.client.config.client === 'mssql') {

5
packages/nocodb/src/lib/migrations/v2/nc_017_add_user_token_version_column.ts

@ -1,13 +1,14 @@
import { Knex } from 'knex';
import { MetaTableOld } from '../../utils/globals';
const up = async (knex: Knex) => {
await knex.schema.alterTable('nc_users_v2', (table) => {
await knex.schema.alterTable(MetaTableOld.USERS, (table) => {
table.string('token_version');
});
};
const down = async (knex) => {
await knex.schema.alterTable('nc_users_v2', (table) => {
await knex.schema.alterTable(MetaTableOld.USERS, (table) => {
table.dropColumns('token_version');
});
};

2
packages/nocodb/src/lib/migrations/v2/nc_018_add_meta_in_view.ts

@ -1,5 +1,5 @@
import { Knex } from 'knex';
import { MetaTable } from '../../utils/globals';
import { MetaTableOld as MetaTable } from '../../utils/globals';
const up = async (knex: Knex) => {
await knex.schema.alterTable(MetaTable.VIEWS, (table) => {

2
packages/nocodb/src/lib/migrations/v2/nc_019_add_meta_in_meta_tables.ts

@ -1,5 +1,5 @@
import { Knex } from 'knex';
import { MetaTable } from '../../utils/globals';
import { MetaTableOld as MetaTable } from '../../utils/globals';
const up = async (knex: Knex) => {
await knex.schema.alterTable(MetaTable.FORM_VIEW, (table) => {

2
packages/nocodb/src/lib/migrations/v2/nc_020_kanban_view.ts

@ -1,5 +1,5 @@
import { Knex } from 'knex';
import { MetaTable } from '../../utils/globals';
import { MetaTableOld as MetaTable } from '../../utils/globals';
const up = async (knex: Knex) => {
await knex.schema.alterTable(MetaTable.KANBAN_VIEW, (table) => {

2
packages/nocodb/src/lib/migrations/v2/nc_021_add_fields_in_token.ts

@ -1,5 +1,5 @@
import { Knex } from 'knex';
import { MetaTable } from '../../utils/globals';
import { MetaTableOld as MetaTable } from '../../utils/globals';
const up = async (knex: Knex) => {
await knex.schema.alterTable(MetaTable.API_TOKENS, (table) => {

2
packages/nocodb/src/lib/migrations/v2/nc_022_qr_code_column_type.ts

@ -1,4 +1,4 @@
import { MetaTable } from '../../utils/globals';
import { MetaTableOld as MetaTable } from '../../utils/globals';
import { Knex } from 'knex';
const up = async (knex: Knex) => {

200
packages/nocodb/src/lib/migrations/v2/nc_023_rename_table.ts

@ -0,0 +1,200 @@
import { MetaTable, MetaTableOld } from '../../utils/globals';
import { Knex } from 'knex';
/***
* Rename v2 meta tables
*
* "nc_audit_v2" => "audit"
* "nc_project_users_v2" => "auth_project_user"
* "nc_users_v2" => "auth_users"
* "nc_bases_v2" => "dbs"
* "nc_col_formula_v2" => "db_col_formula"
* "nc_col_lookup_v2" => "db_col_lookup"
* "nc_col_qrcode_v2" => "db_col_qrcode"
* "nc_col_relations_v2" => "db_col_relation"
* "nc_col_rollup_v2" => "db_col_rollup"
* "nc_col_select_options_v2" => "db_col_select_option"
* "nc_columns_v2" => "db_col"
* "nc_disabled_models_for_role_v2" => "db_disabled_models_for_role"
* "nc_filter_exp_v2" => "db_filter_exp"
* "nc_form_view_v2" => "db_form_view"
* "nc_form_view_columns_v2" => "db_form_view_column"
* "nc_gallery_view_v2" => "db_gallery_view"
* "nc_gallery_view_columns_v2" => "db_gallery_view_column"
* "nc_grid_view_v2" => "db_grid_view"
* "nc_grid_view_columns_v2" => "db_grid_view_column"
* "nc_hook_logs_v2" => "db_webhook_log"
* "nc_hooks_v2" => "db_webhook"
* "nc_kanban_view_v2" => "db_kanban_view"
* "nc_kanban_view_columns_v2" => "db_kanban_view_column"
* "nc_models_v2" => "db_model"
* "nc_shared_views_v2" => "db_shared_view"
* "nc_sort_v2" => "db_sort"
* "nc_sync_logs_v2" => "db_sync_log"
* "nc_sync_source_v2" => "db_sync_source"
* "nc_views_v2" => "db_view"
* "nc_plugins_v2" => "plugin"
* "nc_projects_v2" => "project"
* "nc_store" => "store"
* "nc_api_tokens" => "api_token"
*
*****/
const up = async (knex: Knex) => {
await knex.schema.renameTable(MetaTableOld.AUDIT, MetaTable.AUDIT);
await knex.schema.renameTable(
MetaTableOld.PROJECT_USERS,
MetaTable.PROJECT_USER
);
await knex.schema.renameTable(MetaTableOld.USERS, MetaTable.USER);
await knex.schema.renameTable(MetaTableOld.BASES, MetaTable.BASE);
await knex.schema.renameTable(MetaTableOld.COL_LOOKUP, MetaTable.COL_LOOKUP);
await knex.schema.renameTable(MetaTableOld.COL_ROLLUP, MetaTable.COL_ROLLUP);
await knex.schema.renameTable(
MetaTableOld.COL_FORMULA,
MetaTable.COL_FORMULA
);
await knex.schema.renameTable(MetaTableOld.COL_QRCODE, MetaTable.COL_QRCODE);
await knex.schema.renameTable(
MetaTableOld.COL_RELATIONS,
MetaTable.COL_RELATION
);
await knex.schema.renameTable(
MetaTableOld.COL_SELECT_OPTIONS,
MetaTable.COL_SELECT_OPTION
);
await knex.schema.renameTable(MetaTableOld.COLUMNS, MetaTable.COLUMN);
await knex.schema.renameTable(
MetaTableOld.MODEL_ROLE_VISIBILITY,
MetaTable.MODEL_ROLE_VISIBILITY
);
await knex.schema.renameTable(MetaTableOld.FILTER_EXP, MetaTable.FILTER_EXP);
await knex.schema.renameTable(MetaTableOld.FORM_VIEW, MetaTable.FORM_VIEW);
await knex.schema.renameTable(
MetaTableOld.FORM_VIEW_COLUMNS,
MetaTable.FORM_VIEW_COLUMN
);
await knex.schema.renameTable(
MetaTableOld.GALLERY_VIEW,
MetaTable.GALLERY_VIEW
);
await knex.schema.renameTable(
MetaTableOld.GALLERY_VIEW_COLUMNS,
MetaTable.GALLERY_VIEW_COLUMN
);
await knex.schema.renameTable(MetaTableOld.GRID_VIEW, MetaTable.GRID_VIEW);
await knex.schema.renameTable(
MetaTableOld.GRID_VIEW_COLUMNS,
MetaTable.GRID_VIEW_COLUMN
);
await knex.schema.renameTable(MetaTableOld.HOOK_LOGS, MetaTable.HOOK_LOG);
await knex.schema.renameTable(MetaTableOld.HOOKS, MetaTable.HOOK);
await knex.schema.renameTable(
MetaTableOld.KANBAN_VIEW,
MetaTable.KANBAN_VIEW
);
await knex.schema.renameTable(
MetaTableOld.KANBAN_VIEW_COLUMNS,
MetaTable.KANBAN_VIEW_COLUMN
);
await knex.schema.renameTable(MetaTableOld.MODELS, MetaTable.MODEL);
await knex.schema.renameTable(
MetaTableOld.SHARED_VIEWS,
MetaTable.SHARED_VIEWS
);
await knex.schema.renameTable(MetaTableOld.SORT, MetaTable.SORT);
await knex.schema.renameTable(MetaTableOld.SYNC_LOGS, MetaTable.SYNC_LOG);
await knex.schema.renameTable(
MetaTableOld.SYNC_SOURCE,
MetaTable.SYNC_SOURCE
);
await knex.schema.renameTable(MetaTableOld.VIEWS, MetaTable.VIEW);
await knex.schema.renameTable(MetaTableOld.PLUGIN, MetaTable.PLUGIN);
await knex.schema.renameTable(MetaTableOld.PROJECT, MetaTable.PROJECT);
await knex.schema.renameTable(MetaTableOld.STORE, MetaTable.STORE);
await knex.schema.renameTable(MetaTableOld.API_TOKENS, MetaTable.API_TOKEN);
};
const down = async (knex: Knex) => {
await knex.schema.renameTable(MetaTable.AUDIT, MetaTableOld.AUDIT);
await knex.schema.renameTable(
MetaTable.PROJECT_USER,
MetaTableOld.PROJECT_USERS
);
await knex.schema.renameTable(MetaTable.USER, MetaTableOld.USERS);
await knex.schema.renameTable(MetaTable.BASE, MetaTableOld.BASES);
await knex.schema.renameTable(
MetaTable.FORM_VIEW_COLUMN,
MetaTableOld.FORM_VIEW_COLUMNS
);
await knex.schema.renameTable(MetaTable.COL_LOOKUP, MetaTableOld.COL_LOOKUP);
await knex.schema.renameTable(MetaTable.COL_ROLLUP, MetaTableOld.COL_ROLLUP);
await knex.schema.renameTable(
MetaTable.COL_FORMULA,
MetaTableOld.COL_FORMULA
);
await knex.schema.renameTable(MetaTable.COL_QRCODE, MetaTableOld.COL_QRCODE);
await knex.schema.renameTable(
MetaTable.COL_RELATION,
MetaTableOld.COL_RELATIONS
);
await knex.schema.renameTable(
MetaTable.COL_SELECT_OPTION,
MetaTableOld.COL_SELECT_OPTIONS
);
await knex.schema.renameTable(MetaTable.COLUMN, MetaTableOld.COLUMNS);
await knex.schema.renameTable(
MetaTable.MODEL_ROLE_VISIBILITY,
MetaTableOld.MODEL_ROLE_VISIBILITY
);
await knex.schema.renameTable(MetaTable.FILTER_EXP, MetaTableOld.FILTER_EXP);
await knex.schema.renameTable(MetaTable.FORM_VIEW, MetaTableOld.FORM_VIEW);
await knex.schema.renameTable(
MetaTable.FORM_VIEW_COLUMN,
MetaTableOld.FORM_VIEW_COLUMNS
);
await knex.schema.renameTable(
MetaTable.GALLERY_VIEW,
MetaTableOld.GALLERY_VIEW
);
await knex.schema.renameTable(
MetaTable.GALLERY_VIEW_COLUMN,
MetaTableOld.GALLERY_VIEW_COLUMNS
);
await knex.schema.renameTable(MetaTable.GRID_VIEW, MetaTableOld.GRID_VIEW);
await knex.schema.renameTable(
MetaTable.GRID_VIEW_COLUMN,
MetaTableOld.GRID_VIEW_COLUMNS
);
await knex.schema.renameTable(MetaTable.HOOK_LOG, MetaTableOld.HOOK_LOGS);
await knex.schema.renameTable(MetaTable.HOOK, MetaTableOld.HOOKS);
await knex.schema.renameTable(
MetaTable.KANBAN_VIEW,
MetaTableOld.KANBAN_VIEW
);
await knex.schema.renameTable(
MetaTable.KANBAN_VIEW_COLUMN,
MetaTableOld.KANBAN_VIEW_COLUMNS
);
await knex.schema.renameTable(MetaTable.MODEL, MetaTableOld.MODELS);
await knex.schema.renameTable(
MetaTable.SHARED_VIEWS,
MetaTableOld.SHARED_VIEWS
);
await knex.schema.renameTable(MetaTable.SORT, MetaTableOld.SORT);
await knex.schema.renameTable(MetaTable.SYNC_LOG, MetaTableOld.SYNC_LOGS);
await knex.schema.renameTable(
MetaTable.SYNC_SOURCE,
MetaTableOld.SYNC_SOURCE
);
await knex.schema.renameTable(MetaTable.VIEW, MetaTableOld.VIEWS);
await knex.schema.renameTable(MetaTable.PLUGIN, MetaTableOld.PLUGIN);
await knex.schema.renameTable(MetaTable.PROJECT, MetaTableOld.PROJECT);
await knex.schema.renameTable(MetaTable.STORE, MetaTableOld.STORE);
await knex.schema.renameTable(MetaTable.API_TOKEN, MetaTableOld.API_TOKENS);
};
export { up, down };

23
packages/nocodb/src/lib/migrations/v2/nc_024_delete_table.ts

@ -0,0 +1,23 @@
import { MetaTableOld } from '../../utils/globals';
import { Knex } from 'knex';
/***
* Delete unused v2 meta tables
*
* "nc_orgs_v2"
* "nc_team_users_v2"
* "nc_teams_v2"
*
*****/
const up = async (knex: Knex) => {
await knex.schema.dropTableIfExists(MetaTableOld.TEAM_USERS);
await knex.schema.dropTableIfExists(MetaTableOld.TEAMS);
await knex.schema.dropTableIfExists(MetaTableOld.ORGS);
};
const down = async (_knex: Knex) => {
// not required since we are not using these tables in older versions
};
export { up, down };

40
packages/nocodb/src/lib/models/ApiToken.ts

@ -27,7 +27,7 @@ export default class ApiToken {
ncMeta = Noco.ncMeta
) {
const token = nanoid(40);
await ncMeta.metaInsert(null, null, MetaTable.API_TOKENS, {
await ncMeta.metaInsert(null, null, MetaTable.API_TOKEN, {
description: apiToken.description,
token,
fk_user_id: apiToken.fk_user_id,
@ -43,7 +43,7 @@ export default class ApiToken {
static async list(userId: string, ncMeta = Noco.ncMeta) {
// let tokens = await NocoCache.getList(CacheScope.API_TOKEN, []);
// if (!tokens.length) {
const tokens = await ncMeta.metaList(null, null, MetaTable.API_TOKENS, {
const tokens = await ncMeta.metaList(null, null, MetaTable.API_TOKEN, {
condition: { fk_user_id: userId },
});
// await NocoCache.setList(CacheScope.API_TOKEN, [], tokens);
@ -57,7 +57,7 @@ export default class ApiToken {
`${CacheScope.API_TOKEN}:${token}`,
CacheDelDirection.CHILD_TO_PARENT
);
return await ncMeta.metaDelete(null, null, MetaTable.API_TOKENS, { token });
return await ncMeta.metaDelete(null, null, MetaTable.API_TOKEN, { token });
}
static async getByToken(token, ncMeta = Noco.ncMeta) {
@ -68,7 +68,7 @@ export default class ApiToken {
CacheGetType.TYPE_OBJECT
));
if (!data) {
data = await ncMeta.metaGet(null, null, MetaTable.API_TOKENS, { token });
data = await ncMeta.metaGet(null, null, MetaTable.API_TOKEN, { token });
await NocoCache.set(`${CacheScope.API_TOKEN}:${token}`, data);
}
return data && new ApiToken(data);
@ -81,14 +81,14 @@ export default class ApiToken {
}: { fk_user_id?: string; includeUnmappedToken?: boolean } = {},
ncMeta = Noco.ncMeta
): Promise<number> {
const qb = ncMeta.knex(MetaTable.API_TOKENS);
const qb = ncMeta.knex(MetaTable.API_TOKEN);
if (fk_user_id) {
qb.where(`${MetaTable.API_TOKENS}.fk_user_id`, fk_user_id);
qb.where(`${MetaTable.API_TOKEN}.fk_user_id`, fk_user_id);
}
if (includeUnmappedToken) {
qb.orWhereNull(`${MetaTable.API_TOKENS}.fk_user_id`);
qb.orWhereNull(`${MetaTable.API_TOKEN}.fk_user_id`);
}
return (await qb.count('id', { as: 'count' }).first())?.count ?? 0;
@ -109,34 +109,32 @@ export default class ApiToken {
ncMeta = Noco.ncMeta
) {
const queryBuilder = ncMeta
.knex(MetaTable.API_TOKENS)
.knex(MetaTable.API_TOKEN)
.offset(offset)
.limit(limit)
.select(
`${MetaTable.API_TOKENS}.id`,
`${MetaTable.API_TOKENS}.token`,
`${MetaTable.API_TOKENS}.description`,
`${MetaTable.API_TOKENS}.fk_user_id`,
`${MetaTable.API_TOKENS}.project_id`,
`${MetaTable.API_TOKENS}.created_at`,
`${MetaTable.API_TOKENS}.updated_at`
`${MetaTable.API_TOKEN}.id`,
`${MetaTable.API_TOKEN}.token`,
`${MetaTable.API_TOKEN}.description`,
`${MetaTable.API_TOKEN}.fk_user_id`,
`${MetaTable.API_TOKEN}.project_id`,
`${MetaTable.API_TOKEN}.created_at`,
`${MetaTable.API_TOKEN}.updated_at`
)
.select(
ncMeta
.knex(MetaTable.USERS)
.knex(MetaTable.USER)
.select('email')
.whereRaw(
`${MetaTable.USERS}.id = ${MetaTable.API_TOKENS}.fk_user_id`
)
.whereRaw(`${MetaTable.USER}.id = ${MetaTable.API_TOKEN}.fk_user_id`)
.as('created_by')
);
if (fk_user_id) {
queryBuilder.where(`${MetaTable.API_TOKENS}.fk_user_id`, fk_user_id);
queryBuilder.where(`${MetaTable.API_TOKEN}.fk_user_id`, fk_user_id);
}
if (includeUnmappedToken) {
queryBuilder.orWhereNull(`${MetaTable.API_TOKENS}.fk_user_id`);
queryBuilder.orWhereNull(`${MetaTable.API_TOKEN}.fk_user_id`);
}
return queryBuilder;

14
packages/nocodb/src/lib/models/Base.ts

@ -58,7 +58,7 @@ export default class Base implements BaseType {
const { id } = await ncMeta.metaInsert2(
base.projectId,
null,
MetaTable.BASES,
MetaTable.BASE,
insertObj
);
@ -108,7 +108,7 @@ export default class Base implements BaseType {
'order',
'enabled',
]);
if (updateObj.config) {
updateObj.config = CryptoJS.AES.encrypt(
JSON.stringify(base.config),
@ -154,7 +154,7 @@ export default class Base implements BaseType {
baseDataList = await ncMeta.metaList2(
args.projectId,
null,
MetaTable.BASES,
MetaTable.BASE,
{
orderBy: {
order: 'asc',
@ -181,7 +181,7 @@ export default class Base implements BaseType {
CacheGetType.TYPE_OBJECT
));
if (!baseData) {
baseData = await ncMeta.metaGet2(null, null, MetaTable.BASES, id);
baseData = await ncMeta.metaGet2(null, null, MetaTable.BASE, id);
await NocoCache.set(`${CacheScope.BASE}:${id}`, baseData);
}
return baseData && new Base(baseData);
@ -218,13 +218,13 @@ export default class Base implements BaseType {
await ncMeta.metaUpdate(
b.project_id,
null,
MetaTable.BASES,
MetaTable.BASE,
{
order: b.order
},
b.id
);
await NocoCache.appendToList(
CacheScope.BASE,
[b.project_id],
@ -294,7 +294,7 @@ export default class Base implements BaseType {
await SyncSource.delete(syncSource.id, ncMeta);
}
return await ncMeta.metaDelete(null, null, MetaTable.BASES, this.id);
return await ncMeta.metaDelete(null, null, MetaTable.BASE, this.id);
}
async getModels(ncMeta = Noco.ncMeta) {

40
packages/nocodb/src/lib/models/Column.ts

@ -6,8 +6,8 @@ import SelectOption from './SelectOption';
import Model from './Model';
import NocoCache from '../cache/NocoCache';
import {
ColumnReqType,
AllowedColumnTypesForQrCode,
ColumnReqType,
ColumnType,
UITypes,
} from 'nocodb-sdk';
@ -138,7 +138,7 @@ export default class Column<T = any> implements ColumnType {
const row = await ncMeta.metaInsert2(
null, //column.project_id || column.base_id,
null, //column.db_alias,
MetaTable.COLUMNS,
MetaTable.COLUMN,
insertObj
);
@ -455,7 +455,7 @@ export default class Column<T = any> implements ColumnType {
): Promise<Column[]> {
let columnsList = await NocoCache.getList(CacheScope.COLUMN, [fk_model_id]);
if (!columnsList.length) {
columnsList = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, {
columnsList = await ncMeta.metaList2(null, null, MetaTable.COLUMN, {
condition: {
fk_model_id,
},
@ -548,7 +548,7 @@ export default class Column<T = any> implements ColumnType {
colData = await ncMeta.metaGet2(
base_id,
db_alias,
MetaTable.COLUMNS,
MetaTable.COLUMN,
colId
);
if (colData) {
@ -621,7 +621,7 @@ export default class Column<T = any> implements ColumnType {
col.fk_model_id,
]);
if (!formulaColumns.length) {
formulaColumns = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, {
formulaColumns = await ncMeta.metaList2(null, null, MetaTable.COLUMN, {
condition: {
fk_model_id: col.fk_model_id,
uidt: UITypes.Formula,
@ -712,12 +712,12 @@ export default class Column<T = any> implements ColumnType {
cacheScopeName = CacheScope.COL_LOOKUP;
break;
case UITypes.LinkToAnotherRecord:
colOptionTableName = MetaTable.COL_RELATIONS;
colOptionTableName = MetaTable.COL_RELATION;
cacheScopeName = CacheScope.COL_RELATION;
break;
case UITypes.MultiSelect:
case UITypes.SingleSelect:
colOptionTableName = MetaTable.COL_SELECT_OPTIONS;
colOptionTableName = MetaTable.COL_SELECT_OPTION;
cacheScopeName = CacheScope.COL_SELECT_OPTION;
break;
case UITypes.Formula:
@ -742,7 +742,7 @@ export default class Column<T = any> implements ColumnType {
}
// Grid View Columns
await ncMeta.metaDelete(null, null, MetaTable.GRID_VIEW_COLUMNS, {
await ncMeta.metaDelete(null, null, MetaTable.GRID_VIEW_COLUMN, {
fk_column_id: col.id,
});
const gridViewColumnId = await NocoCache.get(
@ -759,7 +759,7 @@ export default class Column<T = any> implements ColumnType {
}
// Form View Columns
await ncMeta.metaDelete(null, null, MetaTable.FORM_VIEW_COLUMNS, {
await ncMeta.metaDelete(null, null, MetaTable.FORM_VIEW_COLUMN, {
fk_column_id: col.id,
});
const formViewColumnId = await NocoCache.get(
@ -776,7 +776,7 @@ export default class Column<T = any> implements ColumnType {
}
// Kanban View Columns
await ncMeta.metaDelete(null, null, MetaTable.KANBAN_VIEW_COLUMNS, {
await ncMeta.metaDelete(null, null, MetaTable.KANBAN_VIEW_COLUMN, {
fk_column_id: col.id,
});
const kanbanViewColumnId = await NocoCache.get(
@ -793,7 +793,7 @@ export default class Column<T = any> implements ColumnType {
}
// Gallery View Column
await ncMeta.metaDelete(null, null, MetaTable.GALLERY_VIEW_COLUMNS, {
await ncMeta.metaDelete(null, null, MetaTable.GALLERY_VIEW_COLUMN, {
fk_column_id: col.id,
});
const galleryViewColumnId = await NocoCache.get(
@ -813,7 +813,7 @@ export default class Column<T = any> implements ColumnType {
const ltarColumns = await ncMeta.metaList2(
null,
null,
MetaTable.COL_RELATIONS,
MetaTable.COL_RELATION,
{
xcCondition: {
_or: [
@ -832,7 +832,7 @@ export default class Column<T = any> implements ColumnType {
}
// Columns
await ncMeta.metaDelete(null, null, MetaTable.COLUMNS, col.id);
await ncMeta.metaDelete(null, null, MetaTable.COLUMN, col.id);
await NocoCache.deepDel(
CacheScope.COLUMN,
`${CacheScope.COLUMN}:${col.id}`,
@ -870,7 +870,7 @@ export default class Column<T = any> implements ColumnType {
}
case UITypes.LinkToAnotherRecord: {
await ncMeta.metaDelete(null, null, MetaTable.COL_RELATIONS, {
await ncMeta.metaDelete(null, null, MetaTable.COL_RELATION, {
fk_column_id: colId,
});
await NocoCache.deepDel(
@ -907,7 +907,7 @@ export default class Column<T = any> implements ColumnType {
case UITypes.MultiSelect:
case UITypes.SingleSelect: {
await ncMeta.metaDelete(null, null, MetaTable.COL_SELECT_OPTIONS, {
await ncMeta.metaDelete(null, null, MetaTable.COL_SELECT_OPTION, {
fk_column_id: colId,
});
@ -980,7 +980,7 @@ export default class Column<T = any> implements ColumnType {
await ncMeta.metaUpdate(
null,
null,
MetaTable.COLUMNS,
MetaTable.COLUMN,
{
...updateObj,
meta:
@ -1011,7 +1011,7 @@ export default class Column<T = any> implements ColumnType {
await ncMeta.metaUpdate(
null, //column.project_id || column.base_id,
null, //column.db_alias,
MetaTable.COLUMNS,
MetaTable.COLUMN,
{
title,
},
@ -1042,7 +1042,7 @@ export default class Column<T = any> implements ColumnType {
return !(await ncMeta.metaGet2(
null,
null,
MetaTable.COLUMNS,
MetaTable.COLUMN,
{
column_name,
fk_model_id,
@ -1059,7 +1059,7 @@ export default class Column<T = any> implements ColumnType {
return !(await ncMeta.metaGet2(
null,
null,
MetaTable.COLUMNS,
MetaTable.COLUMN,
{
title,
fk_model_id,
@ -1087,7 +1087,7 @@ export default class Column<T = any> implements ColumnType {
await ncMeta.metaUpdate(
null,
null,
MetaTable.COLUMNS,
MetaTable.COLUMN,
{
system,
},

10
packages/nocodb/src/lib/models/FormViewColumn.ts

@ -38,7 +38,7 @@ export default class FormViewColumn implements FormColumnType {
viewColumn = await ncMeta.metaGet2(
null,
null,
MetaTable.FORM_VIEW_COLUMNS,
MetaTable.FORM_VIEW_COLUMN,
formViewColumnId
);
viewColumn.meta =
@ -58,7 +58,7 @@ export default class FormViewColumn implements FormColumnType {
const insertObj: Partial<FormViewColumn> = {
fk_view_id: column.fk_view_id,
fk_column_id: column.fk_column_id,
order: await ncMeta.metaGetNextOrder(MetaTable.FORM_VIEW_COLUMNS, {
order: await ncMeta.metaGetNextOrder(MetaTable.FORM_VIEW_COLUMN, {
fk_view_id: column.fk_view_id,
}),
show: column.show,
@ -83,7 +83,7 @@ export default class FormViewColumn implements FormColumnType {
const { id, fk_column_id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.FORM_VIEW_COLUMNS,
MetaTable.FORM_VIEW_COLUMN,
insertObj
);
@ -116,7 +116,7 @@ export default class FormViewColumn implements FormColumnType {
viewColumns = await ncMeta.metaList2(
null,
null,
MetaTable.FORM_VIEW_COLUMNS,
MetaTable.FORM_VIEW_COLUMN,
{
condition: {
fk_view_id: viewId,
@ -177,7 +177,7 @@ export default class FormViewColumn implements FormColumnType {
await ncMeta.metaUpdate(
null,
null,
MetaTable.FORM_VIEW_COLUMNS,
MetaTable.FORM_VIEW_COLUMN,
insertObj,
columnId
);

8
packages/nocodb/src/lib/models/GalleryViewColumn.ts

@ -29,7 +29,7 @@ export default class GalleryViewColumn {
view = await ncMeta.metaGet2(
null,
null,
MetaTable.GALLERY_VIEW_COLUMNS,
MetaTable.GALLERY_VIEW_COLUMN,
galleryViewColumnId
);
await NocoCache.set(
@ -46,7 +46,7 @@ export default class GalleryViewColumn {
const insertObj = {
fk_view_id: column.fk_view_id,
fk_column_id: column.fk_column_id,
order: await ncMeta.metaGetNextOrder(MetaTable.GALLERY_VIEW_COLUMNS, {
order: await ncMeta.metaGetNextOrder(MetaTable.GALLERY_VIEW_COLUMN, {
fk_view_id: column.fk_view_id,
}),
show: column.show,
@ -63,7 +63,7 @@ export default class GalleryViewColumn {
const { id, fk_column_id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.GALLERY_VIEW_COLUMNS,
MetaTable.GALLERY_VIEW_COLUMN,
insertObj
);
@ -100,7 +100,7 @@ export default class GalleryViewColumn {
views = await ncMeta.metaList2(
null,
null,
MetaTable.GALLERY_VIEW_COLUMNS,
MetaTable.GALLERY_VIEW_COLUMN,
{
condition: {
fk_view_id: viewId,

10
packages/nocodb/src/lib/models/GridViewColumn.ts

@ -26,7 +26,7 @@ export default class GridViewColumn implements GridColumnType {
): Promise<GridViewColumn[]> {
let views = await NocoCache.getList(CacheScope.GRID_VIEW_COLUMN, [viewId]);
if (!views.length) {
views = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, {
views = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMN, {
condition: {
fk_view_id: viewId,
},
@ -55,7 +55,7 @@ export default class GridViewColumn implements GridColumnType {
view = await ncMeta.metaGet2(
null,
null,
MetaTable.GRID_VIEW_COLUMNS,
MetaTable.GRID_VIEW_COLUMN,
gridViewColumnId
);
await NocoCache.set(
@ -72,7 +72,7 @@ export default class GridViewColumn implements GridColumnType {
fk_column_id: column.fk_column_id,
order:
column?.order ??
(await ncMeta.metaGetNextOrder(MetaTable.GRID_VIEW_COLUMNS, {
(await ncMeta.metaGetNextOrder(MetaTable.GRID_VIEW_COLUMN, {
fk_view_id: column.fk_view_id,
})),
show: column.show,
@ -89,7 +89,7 @@ export default class GridViewColumn implements GridColumnType {
const { id, fk_column_id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.GRID_VIEW_COLUMNS,
MetaTable.GRID_VIEW_COLUMN,
insertObj
);
@ -131,7 +131,7 @@ export default class GridViewColumn implements GridColumnType {
await ncMeta.metaUpdate(
null,
null,
MetaTable.GRID_VIEW_COLUMNS,
MetaTable.GRID_VIEW_COLUMN,
updateObj,
columnId
);

10
packages/nocodb/src/lib/models/Hook.ts

@ -46,7 +46,7 @@ export default class Hook implements HookType {
CacheGetType.TYPE_OBJECT
));
if (!hook) {
hook = await ncMeta.metaGet2(null, null, MetaTable.HOOKS, hookId);
hook = await ncMeta.metaGet2(null, null, MetaTable.HOOK, hookId);
await NocoCache.set(`${CacheScope.HOOK}:${hookId}`, hook);
}
return hook && new Hook(hook);
@ -84,7 +84,7 @@ export default class Hook implements HookType {
) {
let hooks = await NocoCache.getList(CacheScope.HOOK, [param.fk_model_id]);
if (!hooks.length) {
hooks = await ncMeta.metaList(null, null, MetaTable.HOOKS, {
hooks = await ncMeta.metaList(null, null, MetaTable.HOOK, {
condition: {
fk_model_id: param.fk_model_id,
// ...(param.event ? { event: param.event?.toLowerCase?.() } : {}),
@ -157,7 +157,7 @@ export default class Hook implements HookType {
const { id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.HOOKS,
MetaTable.HOOK,
insertObj
);
@ -208,7 +208,7 @@ export default class Hook implements HookType {
await NocoCache.set(key, o);
}
// set meta
await ncMeta.metaUpdate(null, null, MetaTable.HOOKS, updateObj, hookId);
await ncMeta.metaUpdate(null, null, MetaTable.HOOK, updateObj, hookId);
return this.get(hookId, ncMeta);
}
@ -237,6 +237,6 @@ export default class Hook implements HookType {
`${CacheScope.HOOK}:${hookId}`,
CacheDelDirection.CHILD_TO_PARENT
);
return await ncMeta.metaDelete(null, null, MetaTable.HOOKS, hookId);
return await ncMeta.metaDelete(null, null, MetaTable.HOOK, hookId);
}
}

4
packages/nocodb/src/lib/models/HookLog.ts

@ -39,7 +39,7 @@ export default class HookLog implements HookLogType {
// todo: redis cache ??
// let hooks = await NocoCache.getList(CacheScope.HOOK, [param.fk_model_id]);
// if (!hooks.length) {
const hookLogs = await ncMeta.metaList(null, null, MetaTable.HOOK_LOGS, {
const hookLogs = await ncMeta.metaList(null, null, MetaTable.HOOK_LOG, {
condition: {
fk_hook_id: param.fk_hook_id,
// ...(param.event ? { event: param.event?.toLowerCase?.() } : {}),
@ -104,6 +104,6 @@ export default class HookLog implements HookLogType {
insertObj.execution_time = parseInt(insertObj.execution_time) || 0;
return await ncMeta.metaInsert2(null, null, MetaTable.HOOK_LOGS, insertObj);
return await ncMeta.metaInsert2(null, null, MetaTable.HOOK_LOG, insertObj);
}
}

27
packages/nocodb/src/lib/models/KanbanViewColumn.ts

@ -29,7 +29,7 @@ export default class KanbanViewColumn {
view = await ncMeta.metaGet2(
null,
null,
MetaTable.KANBAN_VIEW_COLUMNS,
MetaTable.KANBAN_VIEW_COLUMN,
kanbanViewColumnId
);
await NocoCache.set(
@ -43,7 +43,7 @@ export default class KanbanViewColumn {
const insertObj = {
fk_view_id: column.fk_view_id,
fk_column_id: column.fk_column_id,
order: await ncMeta.metaGetNextOrder(MetaTable.KANBAN_VIEW_COLUMNS, {
order: await ncMeta.metaGetNextOrder(MetaTable.KANBAN_VIEW_COLUMN, {
fk_view_id: column.fk_view_id,
}),
show: column.show,
@ -60,7 +60,7 @@ export default class KanbanViewColumn {
const { id, fk_column_id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.KANBAN_VIEW_COLUMNS,
MetaTable.KANBAN_VIEW_COLUMN,
insertObj
);
@ -83,19 +83,14 @@ export default class KanbanViewColumn {
viewId,
]);
if (!views.length) {
views = await ncMeta.metaList2(
null,
null,
MetaTable.KANBAN_VIEW_COLUMNS,
{
condition: {
fk_view_id: viewId,
},
orderBy: {
order: 'asc',
},
}
);
views = await ncMeta.metaList2(null, null, MetaTable.KANBAN_VIEW_COLUMN, {
condition: {
fk_view_id: viewId,
},
orderBy: {
order: 'asc',
},
});
await NocoCache.setList(CacheScope.KANBAN_VIEW_COLUMN, [viewId], views);
}
views.sort(

4
packages/nocodb/src/lib/models/LinkToAnotherRecordColumn.ts

@ -89,7 +89,7 @@ export default class LinkToAnotherRecordColumn {
data: Partial<LinkToAnotherRecordColumn>,
ncMeta = Noco.ncMeta
) {
await ncMeta.metaInsert2(null, null, MetaTable.COL_RELATIONS, {
await ncMeta.metaInsert2(null, null, MetaTable.COL_RELATION, {
fk_column_id: data.fk_column_id,
// ref_db_alias
@ -124,7 +124,7 @@ export default class LinkToAnotherRecordColumn {
colData = await ncMeta.metaGet2(
null, //,
null, //model.db_alias
MetaTable.COL_RELATIONS,
MetaTable.COL_RELATION,
{ fk_column_id: columnId }
);
await NocoCache.set(`${CacheScope.COL_RELATION}:${columnId}`, colData);

42
packages/nocodb/src/lib/models/Model.ts

@ -104,14 +104,14 @@ export default class Model implements TableType {
const { id } = await ncMeta.metaInsert2(
projectId,
baseId,
MetaTable.MODELS,
MetaTable.MODEL,
{
table_name: model.table_name,
title: model.title,
mm: !!model.mm,
order:
model.order ||
(await ncMeta.metaGetNextOrder(MetaTable.FORM_VIEW_COLUMNS, {
(await ncMeta.metaGetNextOrder(MetaTable.FORM_VIEW_COLUMN, {
project_id: projectId,
base_id: baseId,
})),
@ -167,7 +167,7 @@ export default class Model implements TableType {
modelList = await ncMeta.metaList2(
project_id,
base_id,
MetaTable.MODELS,
MetaTable.MODEL,
{
orderBy: {
order: 'asc',
@ -207,7 +207,7 @@ export default class Model implements TableType {
modelList = await ncMeta.metaList2(
project_id,
db_alias,
MetaTable.MODELS
MetaTable.MODEL
);
await NocoCache.setList(CacheScope.MODEL, [project_id], modelList);
@ -229,7 +229,7 @@ export default class Model implements TableType {
CacheGetType.TYPE_OBJECT
));
if (!modelData) {
modelData = await ncMeta.metaGet2(null, null, MetaTable.MODELS, id);
modelData = await ncMeta.metaGet2(null, null, MetaTable.MODEL, id);
if (modelData)
await NocoCache.set(`${CacheScope.MODEL}:${modelData.id}`, modelData);
}
@ -256,7 +256,7 @@ export default class Model implements TableType {
CacheGetType.TYPE_OBJECT
));
if (!modelData) {
modelData = await ncMeta.metaGet2(null, null, MetaTable.MODELS, k);
modelData = await ncMeta.metaGet2(null, null, MetaTable.MODEL, k);
// if (
// this.baseModels?.[modelData.base_id]?.[modelData.db_alias]?.[
// modelData.title
@ -303,7 +303,7 @@ export default class Model implements TableType {
modelData = await ncMeta.metaGet2(
null,
null,
MetaTable.MODELS,
MetaTable.MODEL,
id || {
table_name,
}
@ -363,12 +363,12 @@ export default class Model implements TableType {
break;
case UITypes.ForeignKey:
case UITypes.LinkToAnotherRecord:
colOptionTableName = MetaTable.COL_RELATIONS;
colOptionTableName = MetaTable.COL_RELATION;
cacheScopeName = CacheScope.COL_RELATION;
break;
case UITypes.MultiSelect:
case UITypes.SingleSelect:
colOptionTableName = MetaTable.COL_SELECT_OPTIONS;
colOptionTableName = MetaTable.COL_SELECT_OPTION;
cacheScopeName = CacheScope.COL_SELECT_OPTION;
break;
case UITypes.Formula:
@ -393,7 +393,7 @@ export default class Model implements TableType {
`${CacheScope.COLUMN}:${this.id}`,
CacheDelDirection.CHILD_TO_PARENT
);
await ncMeta.metaDelete(null, null, MetaTable.COLUMNS, {
await ncMeta.metaDelete(null, null, MetaTable.COLUMN, {
fk_model_id: this.id,
});
@ -402,7 +402,7 @@ export default class Model implements TableType {
`${CacheScope.MODEL}:${this.id}`,
CacheDelDirection.CHILD_TO_PARENT
);
await ncMeta.metaDelete(null, null, MetaTable.MODELS, this.id);
await ncMeta.metaDelete(null, null, MetaTable.MODEL, this.id);
await NocoCache.del(`${CacheScope.MODEL}:${this.project_id}:${this.id}`);
await NocoCache.del(`${CacheScope.MODEL}:${this.project_id}:${this.title}`);
@ -450,7 +450,7 @@ export default class Model implements TableType {
return await ncMeta.metaUpdate(
null,
null,
MetaTable.MODELS,
MetaTable.MODEL,
{
title,
table_name,
@ -473,7 +473,7 @@ export default class Model implements TableType {
return await ncMeta.metaUpdate(
null,
null,
MetaTable.MODELS,
MetaTable.MODEL,
{
mm: isMm,
},
@ -516,7 +516,7 @@ export default class Model implements TableType {
return await ncMeta.metaUpdate(
null,
null,
MetaTable.MODELS,
MetaTable.MODEL,
{
order,
},
@ -548,7 +548,7 @@ export default class Model implements TableType {
await ncMeta.metaUpdate(
null,
null,
MetaTable.COLUMNS,
MetaTable.COLUMN,
{
pv: false,
},
@ -568,7 +568,7 @@ export default class Model implements TableType {
await ncMeta.metaUpdate(
null,
null,
MetaTable.COLUMNS,
MetaTable.COLUMN,
{
pv: true,
},
@ -591,7 +591,7 @@ export default class Model implements TableType {
await ncMeta.metaUpdate(
null,
null,
MetaTable.MODELS,
MetaTable.MODEL,
{
mm: true,
},
@ -623,7 +623,7 @@ export default class Model implements TableType {
? await ncMeta.metaGet2(
null,
null,
MetaTable.MODELS,
MetaTable.MODEL,
{ project_id, base_id },
null,
{
@ -644,7 +644,7 @@ export default class Model implements TableType {
: await ncMeta.metaGet2(
null,
null,
MetaTable.MODELS,
MetaTable.MODEL,
{ project_id },
null,
{
@ -686,7 +686,7 @@ export default class Model implements TableType {
return !(await ncMeta.metaGet2(
project_id,
base_id,
MetaTable.MODELS,
MetaTable.MODEL,
{
table_name,
},
@ -707,7 +707,7 @@ export default class Model implements TableType {
return !(await ncMeta.metaGet2(
project_id,
base_id,
MetaTable.MODELS,
MetaTable.MODEL,
{
title,
},

42
packages/nocodb/src/lib/models/ProjectUser.ts

@ -25,7 +25,7 @@ export default class ProjectUser {
const { project_id, fk_user_id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.PROJECT_USERS,
MetaTable.PROJECT_USER,
{
fk_user_id: projectUser.fk_user_id,
project_id: projectUser.project_id,
@ -57,7 +57,7 @@ export default class ProjectUser {
CacheGetType.TYPE_OBJECT
));
if (!projectUser) {
projectUser = await ncMeta.metaGet2(null, null, MetaTable.PROJECT_USERS, {
projectUser = await ncMeta.metaGet2(null, null, MetaTable.PROJECT_USER, {
fk_user_id: userId,
project_id: projectId,
});
@ -84,14 +84,14 @@ export default class ProjectUser {
ncMeta = Noco.ncMeta
) {
const queryBuilder = ncMeta
.knex(MetaTable.USERS)
.knex(MetaTable.USER)
.select(
`${MetaTable.USERS}.id`,
`${MetaTable.USERS}.email`,
`${MetaTable.USERS}.invite_token`,
`${MetaTable.USERS}.roles as main_roles`,
`${MetaTable.PROJECT_USERS}.project_id`,
`${MetaTable.PROJECT_USERS}.roles as roles`
`${MetaTable.USER}.id`,
`${MetaTable.USER}.email`,
`${MetaTable.USER}.invite_token`,
`${MetaTable.USER}.roles as main_roles`,
`${MetaTable.PROJECT_USER}.project_id`,
`${MetaTable.PROJECT_USER}.roles as roles`
)
.offset(offset)
.limit(limit);
@ -100,13 +100,13 @@ export default class ProjectUser {
queryBuilder.where('email', 'like', `%${query.toLowerCase?.()}%`);
}
queryBuilder.leftJoin(MetaTable.PROJECT_USERS, function () {
queryBuilder.leftJoin(MetaTable.PROJECT_USER, function () {
this.on(
`${MetaTable.PROJECT_USERS}.fk_user_id`,
`${MetaTable.PROJECT_USER}.fk_user_id`,
'=',
`${MetaTable.USERS}.id`
`${MetaTable.USER}.id`
).andOn(
`${MetaTable.PROJECT_USERS}.project_id`,
`${MetaTable.PROJECT_USER}.project_id`,
'=',
ncMeta.knex.raw('?', [project_id])
);
@ -123,7 +123,7 @@ export default class ProjectUser {
},
ncMeta = Noco.ncMeta
): Promise<number> {
const qb = ncMeta.knex(MetaTable.USERS);
const qb = ncMeta.knex(MetaTable.USER);
if (query) {
qb.where('email', 'like', `%${query.toLowerCase?.()}%`);
@ -161,7 +161,7 @@ export default class ProjectUser {
return await ncMeta.metaUpdate(
null,
null,
MetaTable.PROJECT_USERS,
MetaTable.PROJECT_USER,
{
roles,
},
@ -178,7 +178,7 @@ export default class ProjectUser {
// `${CacheScope.PROJECT_USER}:${projectId}:${userId}`,
// CacheDelDirection.CHILD_TO_PARENT
// );
const { email } = await ncMeta.metaGet2(null, null, MetaTable.USERS, {
const { email } = await ncMeta.metaGet2(null, null, MetaTable.USER, {
id: userId,
});
if (email) {
@ -199,7 +199,7 @@ export default class ProjectUser {
}
await NocoCache.del(`${CacheScope.PROJECT_USER}:${projectId}:${userId}`);
return await ncMeta.metaDelete(null, null, MetaTable.PROJECT_USERS, {
return await ncMeta.metaDelete(null, null, MetaTable.PROJECT_USER, {
fk_user_id: userId,
project_id: projectId,
});
@ -209,7 +209,7 @@ export default class ProjectUser {
userId: string,
ncMeta = Noco.ncMeta
): Promise<ProjectUser[]> {
return await ncMeta.metaList2(null, null, MetaTable.PROJECT_USERS, {
return await ncMeta.metaList2(null, null, MetaTable.PROJECT_USER, {
condition: { fk_user_id: userId },
});
}
@ -231,13 +231,13 @@ export default class ProjectUser {
projectList = await ncMeta
.knex(MetaTable.PROJECT)
.select(`${MetaTable.PROJECT}.*`)
.innerJoin(MetaTable.PROJECT_USERS, function () {
.innerJoin(MetaTable.PROJECT_USER, function () {
this.on(
`${MetaTable.PROJECT_USERS}.project_id`,
`${MetaTable.PROJECT_USER}.project_id`,
`${MetaTable.PROJECT}.id`
);
this.andOn(
`${MetaTable.PROJECT_USERS}.fk_user_id`,
`${MetaTable.PROJECT_USER}.fk_user_id`,
ncMeta.knex.raw('?', [userId])
);
})

8
packages/nocodb/src/lib/models/SelectOption.ts

@ -19,7 +19,7 @@ export default class SelectOption {
const { id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.COL_SELECT_OPTIONS,
MetaTable.COL_SELECT_OPTION,
data
);
@ -46,7 +46,7 @@ export default class SelectOption {
data = await ncMeta.metaGet2(
null,
null,
MetaTable.COL_SELECT_OPTIONS,
MetaTable.COL_SELECT_OPTION,
selectOptionId
);
await NocoCache.set(
@ -65,7 +65,7 @@ export default class SelectOption {
options = await ncMeta.metaList2(
null, //,
null, //model.db_alias,
MetaTable.COL_SELECT_OPTIONS,
MetaTable.COL_SELECT_OPTION,
{ condition: { fk_column_id } }
);
await NocoCache.setList(
@ -92,7 +92,7 @@ export default class SelectOption {
const data = await ncMeta.metaGet2(
null,
null,
MetaTable.COL_SELECT_OPTIONS,
MetaTable.COL_SELECT_OPTION,
{
fk_column_id,
title,

6
packages/nocodb/src/lib/models/SyncLogs.ts

@ -14,7 +14,7 @@ export default class SyncLogs {
}
static async list(projectId: string, ncMeta = Noco.ncMeta) {
const syncLogs = await ncMeta.metaList(null, null, MetaTable.SYNC_LOGS, {
const syncLogs = await ncMeta.metaList(null, null, MetaTable.SYNC_LOG, {
condition: {
project_id: projectId,
},
@ -45,13 +45,13 @@ export default class SyncLogs {
const { id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.SYNC_LOGS,
MetaTable.SYNC_LOG,
insertObj
);
return new SyncLogs({ ...insertObj, id });
}
static async delete(syncLogId: any, ncMeta = Noco.ncMeta) {
return await ncMeta.metaDelete(null, null, MetaTable.SYNC_LOGS, syncLogId);
return await ncMeta.metaDelete(null, null, MetaTable.SYNC_LOG, syncLogId);
}
}

42
packages/nocodb/src/lib/models/User.ts

@ -57,7 +57,7 @@ export default class User implements UserType {
const { id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.USERS,
MetaTable.USER,
insertObj
);
@ -116,7 +116,7 @@ export default class User implements UserType {
}
// set meta
return await ncMeta.metaUpdate(null, null, MetaTable.USERS, updateObj, id);
return await ncMeta.metaUpdate(null, null, MetaTable.USER, updateObj, id);
}
public static async getByEmail(_email: string, ncMeta = Noco.ncMeta) {
@ -128,7 +128,7 @@ export default class User implements UserType {
CacheGetType.TYPE_OBJECT
));
if (!user) {
user = await ncMeta.metaGet2(null, null, MetaTable.USERS, {
user = await ncMeta.metaGet2(null, null, MetaTable.USER, {
email,
});
await NocoCache.set(`${CacheScope.USER}:${email}`, user);
@ -139,7 +139,7 @@ export default class User implements UserType {
static async isFirst(ncMeta = Noco.ncMeta) {
const isFirst = !(await NocoCache.getAll(`${CacheScope.USER}:*`))?.length;
if (isFirst)
return !(await ncMeta.metaGet2(null, null, MetaTable.USERS, {}));
return !(await ncMeta.metaGet2(null, null, MetaTable.USER, {}));
return false;
}
@ -151,7 +151,7 @@ export default class User implements UserType {
} = {},
ncMeta = Noco.ncMeta
): Promise<number> {
const qb = ncMeta.knex(MetaTable.USERS);
const qb = ncMeta.knex(MetaTable.USER);
if (query) {
qb.where('email', 'like', `%${query.toLowerCase?.()}%`);
@ -168,14 +168,14 @@ export default class User implements UserType {
CacheGetType.TYPE_OBJECT
));
if (!user) {
user = await ncMeta.metaGet2(null, null, MetaTable.USERS, userId);
user = await ncMeta.metaGet2(null, null, MetaTable.USER, userId);
await NocoCache.set(`${CacheScope.USER}:${userId}`, user);
}
return user;
}
static async getByRefreshToken(refresh_token, ncMeta = Noco.ncMeta) {
const user = await ncMeta.metaGet2(null, null, MetaTable.USERS, {
const user = await ncMeta.metaGet2(null, null, MetaTable.USER, {
refresh_token,
});
return user;
@ -193,7 +193,7 @@ export default class User implements UserType {
} = {},
ncMeta = Noco.ncMeta
) {
let queryBuilder = ncMeta.knex(MetaTable.USERS);
let queryBuilder = ncMeta.knex(MetaTable.USER);
if (offset) queryBuilder = queryBuilder.offset(offset);
@ -201,23 +201,23 @@ export default class User implements UserType {
queryBuilder = queryBuilder
.select(
`${MetaTable.USERS}.id`,
`${MetaTable.USERS}.email`,
`${MetaTable.USERS}.firstname`,
`${MetaTable.USERS}.lastname`,
`${MetaTable.USERS}.username`,
`${MetaTable.USERS}.email_verified`,
`${MetaTable.USERS}.invite_token`,
`${MetaTable.USERS}.created_at`,
`${MetaTable.USERS}.updated_at`,
`${MetaTable.USERS}.roles`
`${MetaTable.USER}.id`,
`${MetaTable.USER}.email`,
`${MetaTable.USER}.firstname`,
`${MetaTable.USER}.lastname`,
`${MetaTable.USER}.username`,
`${MetaTable.USER}.email_verified`,
`${MetaTable.USER}.invite_token`,
`${MetaTable.USER}.created_at`,
`${MetaTable.USER}.updated_at`,
`${MetaTable.USER}.roles`
)
.select(
ncMeta
.knex(MetaTable.PROJECT_USERS)
.knex(MetaTable.PROJECT_USER)
.count()
.whereRaw(
`${MetaTable.USERS}.id = ${MetaTable.PROJECT_USERS}.fk_user_id`
`${MetaTable.USER}.id = ${MetaTable.PROJECT_USER}.fk_user_id`
)
.as('projectsCount')
);
@ -241,6 +241,6 @@ export default class User implements UserType {
await NocoCache.del(`${CacheScope.USER}:${userId}`);
await NocoCache.del(`${CacheScope.USER}:${user.email}`);
await ncMeta.metaDelete(null, null, MetaTable.USERS, userId);
await ncMeta.metaDelete(null, null, MetaTable.USER, userId);
}
}

44
packages/nocodb/src/lib/models/View.ts

@ -117,7 +117,7 @@ export default class View implements ViewType {
CacheGetType.TYPE_OBJECT
));
if (!view) {
view = await ncMeta.metaGet2(null, null, MetaTable.VIEWS, viewId);
view = await ncMeta.metaGet2(null, null, MetaTable.VIEW, viewId);
await NocoCache.set(`${CacheScope.VIEW}:${view.id}`, view);
}
@ -138,7 +138,7 @@ export default class View implements ViewType {
const view = await ncMeta.metaGet2(
null,
null,
MetaTable.VIEWS,
MetaTable.VIEW,
{ fk_model_id },
null,
{
@ -181,7 +181,7 @@ export default class View implements ViewType {
view = await ncMeta.metaGet2(
null,
null,
MetaTable.VIEWS,
MetaTable.VIEW,
{
fk_model_id,
is_default: 1,
@ -196,7 +196,7 @@ export default class View implements ViewType {
public static async list(modelId: string, ncMeta = Noco.ncMeta) {
let viewsList = await NocoCache.getList(CacheScope.VIEW, [modelId]);
if (!viewsList.length) {
viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, {
viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEW, {
condition: {
fk_model_id: modelId,
},
@ -238,7 +238,7 @@ export default class View implements ViewType {
ncMeta = Noco.ncMeta
) {
// get order value
const order = await ncMeta.metaGetNextOrder(MetaTable.VIEWS, {
const order = await ncMeta.metaGetNextOrder(MetaTable.VIEW, {
fk_model_id: view.fk_model_id,
});
@ -270,7 +270,7 @@ export default class View implements ViewType {
const { id: view_id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.VIEWS,
MetaTable.VIEW,
insertObj
);
@ -602,19 +602,19 @@ export default class View implements ViewType {
let cacheScope;
switch (view.type) {
case ViewTypes.GRID:
table = MetaTable.GRID_VIEW_COLUMNS;
table = MetaTable.GRID_VIEW_COLUMN;
cacheScope = CacheScope.GRID_VIEW_COLUMN;
break;
case ViewTypes.GALLERY:
table = MetaTable.GALLERY_VIEW_COLUMNS;
table = MetaTable.GALLERY_VIEW_COLUMN;
cacheScope = CacheScope.GALLERY_VIEW_COLUMN;
break;
case ViewTypes.KANBAN:
table = MetaTable.KANBAN_VIEW_COLUMNS;
table = MetaTable.KANBAN_VIEW_COLUMN;
cacheScope = CacheScope.KANBAN_VIEW_COLUMN;
break;
case ViewTypes.FORM:
table = MetaTable.FORM_VIEW_COLUMNS;
table = MetaTable.FORM_VIEW_COLUMN;
cacheScope = CacheScope.FORM_VIEW_COLUMN;
break;
}
@ -708,7 +708,7 @@ export default class View implements ViewType {
}
static async getByUUID(uuid: string, ncMeta = Noco.ncMeta) {
const view = await ncMeta.metaGet2(null, null, MetaTable.VIEWS, {
const view = await ncMeta.metaGet2(null, null, MetaTable.VIEW, {
uuid,
});
@ -733,7 +733,7 @@ export default class View implements ViewType {
await ncMeta.metaUpdate(
null,
null,
MetaTable.VIEWS,
MetaTable.VIEW,
{
uuid: view.uuid,
},
@ -757,7 +757,7 @@ export default class View implements ViewType {
await ncMeta.metaUpdate(
null,
null,
MetaTable.VIEWS,
MetaTable.VIEW,
{
meta: JSON.stringify(defaultMeta),
},
@ -786,7 +786,7 @@ export default class View implements ViewType {
await ncMeta.metaUpdate(
null,
null,
MetaTable.VIEWS,
MetaTable.VIEW,
{
password,
},
@ -808,7 +808,7 @@ export default class View implements ViewType {
await ncMeta.metaUpdate(
null,
null,
MetaTable.VIEWS,
MetaTable.VIEW,
{
uuid: null,
},
@ -855,7 +855,7 @@ export default class View implements ViewType {
await NocoCache.set(key, o);
}
// set meta
await ncMeta.metaUpdate(null, null, MetaTable.VIEWS, updateObj, viewId);
await ncMeta.metaUpdate(null, null, MetaTable.VIEW, updateObj, viewId);
return this.get(viewId);
}
@ -884,7 +884,7 @@ export default class View implements ViewType {
`${columnTableScope}:${viewId}`,
CacheDelDirection.CHILD_TO_PARENT
);
await ncMeta.metaDelete(null, null, MetaTable.VIEWS, viewId);
await ncMeta.metaDelete(null, null, MetaTable.VIEW, viewId);
await NocoCache.deepDel(
CacheScope.VIEW,
`${CacheScope.VIEW}:${viewId}`,
@ -898,16 +898,16 @@ export default class View implements ViewType {
let table;
switch (view.type) {
case ViewTypes.GRID:
table = MetaTable.GRID_VIEW_COLUMNS;
table = MetaTable.GRID_VIEW_COLUMN;
break;
case ViewTypes.GALLERY:
table = MetaTable.GALLERY_VIEW_COLUMNS;
table = MetaTable.GALLERY_VIEW_COLUMN;
break;
case ViewTypes.KANBAN:
table = MetaTable.KANBAN_VIEW_COLUMNS;
table = MetaTable.KANBAN_VIEW_COLUMN;
break;
case ViewTypes.FORM:
table = MetaTable.FORM_VIEW_COLUMNS;
table = MetaTable.FORM_VIEW_COLUMN;
break;
}
return table;
@ -1095,7 +1095,7 @@ export default class View implements ViewType {
static async shareViewList(tableId, ncMeta = Noco.ncMeta) {
let sharedViews = await NocoCache.getList(CacheScope.VIEW, [tableId]);
if (!sharedViews.length) {
sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEWS, {
sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEW, {
xcCondition: {
fk_model_id: {
eq: tableId,

2
packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts

@ -3,8 +3,8 @@ import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import {
waitForStreamClose,
generateTempFilePath,
waitForStreamClose,
} from '../../utils/pluginUtils';
export default class Backblaze implements IStorageAdapterV2 {

2
packages/nocodb/src/lib/plugins/gcs/Gcs.ts

@ -3,8 +3,8 @@ import { Storage, StorageOptions } from '@google-cloud/storage';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import {
waitForStreamClose,
generateTempFilePath,
waitForStreamClose,
} from '../../utils/pluginUtils';
export default class Gcs implements IStorageAdapterV2 {

2
packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts

@ -3,8 +3,8 @@ import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import {
waitForStreamClose,
generateTempFilePath,
waitForStreamClose,
} from '../../utils/pluginUtils';
export default class LinodeObjectStorage implements IStorageAdapterV2 {

2
packages/nocodb/src/lib/plugins/mino/Minio.ts

@ -3,8 +3,8 @@ import { Client as MinioClient } from 'minio';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import {
waitForStreamClose,
generateTempFilePath,
waitForStreamClose,
} from '../../utils/pluginUtils';
export default class Minio implements IStorageAdapterV2 {

2
packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts

@ -3,8 +3,8 @@ import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import {
waitForStreamClose,
generateTempFilePath,
waitForStreamClose,
} from '../../utils/pluginUtils';
export default class OvhCloud implements IStorageAdapterV2 {

2
packages/nocodb/src/lib/plugins/s3/S3.ts

@ -3,8 +3,8 @@ import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import {
waitForStreamClose,
generateTempFilePath,
waitForStreamClose,
} from '../../utils/pluginUtils';
export default class S3 implements IStorageAdapterV2 {

2
packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts

@ -3,8 +3,8 @@ import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import AWS from 'aws-sdk';
import request from 'request';
import {
waitForStreamClose,
generateTempFilePath,
waitForStreamClose,
} from '../../utils/pluginUtils';
export default class ScalewayObjectStorage implements IStorageAdapterV2 {

2
packages/nocodb/src/lib/plugins/spaces/Spaces.ts

@ -3,8 +3,8 @@ import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import {
waitForStreamClose,
generateTempFilePath,
waitForStreamClose,
} from '../../utils/pluginUtils';
export default class Spaces implements IStorageAdapterV2 {

2
packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts

@ -3,8 +3,8 @@ import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import {
waitForStreamClose,
generateTempFilePath,
waitForStreamClose,
} from '../../utils/pluginUtils';
export default class UpoCloud implements IStorageAdapterV2 {

2
packages/nocodb/src/lib/plugins/vultr/Vultr.ts

@ -3,8 +3,8 @@ import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import {
waitForStreamClose,
generateTempFilePath,
waitForStreamClose,
} from '../../utils/pluginUtils';
export default class Vultr implements IStorageAdapterV2 {

17
packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts

@ -16,6 +16,7 @@ import { Acls, DbConfig, NcConfig } from '../../../interface/config';
import { BaseModelSql, XKnex } from '../../db/sql-data-mapper';
import ModelXcMetaFactory from '../../db/sql-mgr/code/models/xc/ModelXcMetaFactory';
import ExpressXcPolicy from '../../db/sql-mgr/code/policies/xc/ExpressXcPolicy';
import { MetaTable, MetaTableV1 } from '../globals'
import NcHelp from '../NcHelp';
import NcProjectBuilder from '../../v1-legacy/NcProjectBuilder';
import Noco from '../../Noco';
@ -1322,7 +1323,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
{ name: '0083008', handler: ncRemoveDuplicatedRelationRows },
{ name: '0084002', handler: this.ncUpAddNestedResolverArgs.bind(this) },
];
if (!(await this.xcMeta?.knex?.schema?.hasTable?.('nc_store'))) {
if (!(await this.xcMeta?.knex?.schema?.hasTable?.(MetaTable.STORE))) {
return;
}
this.baseLog(`xcUpgrade : Getting configuration from meta database`);
@ -1330,7 +1331,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
const config = await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_store',
MetaTable.STORE,
{ key: 'NC_CONFIG' }
);
@ -1357,7 +1358,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_store',
MetaTable.STORE,
{
value: JSON.stringify(configObj),
},
@ -1376,7 +1377,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_store',
MetaTable.STORE,
{
value: JSON.stringify(configObj),
},
@ -1393,7 +1394,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
await this.xcMeta.metaList(this.projectId, this.dbAlias, 'nc_models')
)?.length;
configObj.version = isOld ? '0009000' : process.env.NC_VERSION;
await this.xcMeta.metaInsert(this.projectId, this.dbAlias, 'nc_store', {
await this.xcMeta.metaInsert(this.projectId, this.dbAlias, MetaTable.STORE, {
key: 'NC_CONFIG',
value: JSON.stringify(configObj),
});
@ -1818,6 +1819,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
);
}
// required
protected generateContextForTable(
tn: string,
columns: any[],
@ -2480,7 +2482,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
const models = await this.xcMeta.metaList(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
fields: ['meta'],
condition: {
@ -2520,7 +2522,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
meta: JSON.stringify(meta),
},
@ -2533,6 +2535,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
return metas;
}
// required
private getColumnNameAlias(col, tableName?: string) {
return (
this.metas?.[tableName]?.columns?.find((c) => c.cn === col.cn)?._cn ||

9
packages/nocodb/src/lib/utils/common/jobs/ncModelsOrderUpgrader.ts

@ -1,10 +1,11 @@
import { MetaTableV1 } from '../../globals';
import { NcBuilderUpgraderCtx } from '../BaseApiBuilder';
export default async function (ctx: NcBuilderUpgraderCtx) {
const models = await ctx.xcMeta.metaList(
ctx.projectId,
ctx.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
xcCondition: {
_or: [{ type: { eq: 'table' } }, { type: { eq: 'view' } }],
@ -16,7 +17,7 @@ export default async function (ctx: NcBuilderUpgraderCtx) {
await ctx.xcMeta.metaUpdate(
ctx.projectId,
ctx.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
order: ++order,
view_order: 1,
@ -27,7 +28,7 @@ export default async function (ctx: NcBuilderUpgraderCtx) {
const views = await ctx.xcMeta.metaList(
ctx.projectId,
ctx.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
condition: { parent_model_title: model.title },
}
@ -37,7 +38,7 @@ export default async function (ctx: NcBuilderUpgraderCtx) {
await ctx.xcMeta.metaUpdate(
ctx.projectId,
ctx.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
view_order: ++view_order,
},

5
packages/nocodb/src/lib/utils/common/jobs/ncParentModelTitleUpgrader.ts

@ -1,10 +1,11 @@
import { MetaTableV1 } from '../../globals';
import { NcBuilderUpgraderCtx } from '../BaseApiBuilder';
export default async function (ctx: NcBuilderUpgraderCtx) {
const views = await ctx.xcMeta.metaList(
ctx.projectId,
ctx.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
condition: {
type: 'vtable',
@ -16,7 +17,7 @@ export default async function (ctx: NcBuilderUpgraderCtx) {
await ctx.xcMeta.metaUpdate(
ctx.projectId,
ctx.dbAlias,
'nc_disabled_models_for_role',
MetaTableV1.DISABLED_MODELS_FOR_ROLE,
{
parent_model_title: view.parent_model_title,
},

11
packages/nocodb/src/lib/utils/common/jobs/ncRemoveDuplicatedRelationRows.ts

@ -1,3 +1,4 @@
import { MetaTableV1 } from '../../globals';
import { NcBuilderUpgraderCtx } from '../BaseApiBuilder';
export default async function (ctx: NcBuilderUpgraderCtx) {
@ -5,7 +6,7 @@ export default async function (ctx: NcBuilderUpgraderCtx) {
const relations = await ctx.xcMeta.metaList(
ctx.projectId,
ctx.dbAlias,
'nc_relations'
MetaTableV1.RELATIONS
);
const duplicates = [];
@ -30,7 +31,7 @@ export default async function (ctx: NcBuilderUpgraderCtx) {
await ctx.xcMeta.metaDelete(
ctx.projectId,
ctx.dbAlias,
'nc_relations',
MetaTableV1.RELATIONS,
dupRelation.id
);
{
@ -62,7 +63,7 @@ export default async function (ctx: NcBuilderUpgraderCtx) {
await ctx.xcMeta.metaUpdate(
ctx.projectId,
ctx.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{ meta: JSON.stringify(meta) },
{
type: 'table',
@ -74,7 +75,7 @@ export default async function (ctx: NcBuilderUpgraderCtx) {
const rtnModel = await ctx.xcMeta.metaGet(
ctx.projectId,
ctx.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
type: 'table',
title: dupRelation.rtn,
@ -98,7 +99,7 @@ export default async function (ctx: NcBuilderUpgraderCtx) {
await ctx.xcMeta.metaUpdate(
ctx.projectId,
ctx.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{ meta: JSON.stringify(meta) },
{
type: 'table',

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

@ -24,12 +24,12 @@ export default async function (force = false, ncMeta = Noco.ncMeta) {
.where('is_meta', false)
.then((c) => c.count);
const impacted = await ncMeta
.knex(MetaTable.USERS)
.knex(MetaTable.USER)
.count('id as count')
.first()
.then((c) => c.count);
const created = await ncMeta
.knex('nc_store')
.knex(MetaTable.STORE)
.select('created_at')
.where('key', 'nc_server_id')
.first()

85
packages/nocodb/src/lib/utils/globals.ts

@ -1,4 +1,41 @@
export enum MetaTable {
PROJECT = 'project',
BASE = 'db',
MODEL = 'db_model',
COLUMN = 'db_col',
COL_RELATION = 'db_col_relation',
COL_SELECT_OPTION = 'db_col_select_option',
COL_LOOKUP = 'db_col_lookup',
COL_ROLLUP = 'db_col_rollup',
COL_FORMULA = 'db_col_formula',
COL_QRCODE = 'db_col_qrcode',
FILTER_EXP = 'db_filter_exp',
SORT = 'db_sort',
SHARED_VIEWS = 'db_shared_view',
FORM_VIEW = 'db_form_view',
FORM_VIEW_COLUMN = 'db_form_view_column',
GALLERY_VIEW = 'db_gallery_view',
GALLERY_VIEW_COLUMN = 'db_gallery_view_column',
GRID_VIEW = 'db_grid_view',
GRID_VIEW_COLUMN = 'db_grid_view_column',
KANBAN_VIEW = 'db_kanban_view',
KANBAN_VIEW_COLUMN = 'db_kanban_view_column',
USER = 'auth_user',
VIEW = 'db_view',
AUDIT = 'audit',
HOOK = 'db_webhook',
HOOK_LOG = 'db_webhook_log',
PLUGIN = 'plugin',
PROJECT_USER = 'auth_project_user',
MODEL_ROLE_VISIBILITY = 'db_disabled_models_for_role',
API_TOKEN = 'nc_api_token',
SYNC_SOURCE = 'db_sync_log',
SYNC_LOG = 'db_sync_source',
STORE = 'store',
}
// Reference of old meta table names which no longer exists
export enum MetaTableOld {
PROJECT = 'nc_projects_v2',
BASES = 'nc_bases_v2',
MODELS = 'nc_models_v2',
@ -41,38 +78,49 @@ export enum MetaTable {
STORE = 'nc_store',
}
export enum MetaTableV1 {
ACL = 'z_acl',
AUDIT = 'z_audit',
DISABLED_MODELS_FOR_ROLE = 'z_disabled_models_for_role',
HOOKS = 'z_hooks',
MIGRATIONS = 'z_migrations',
MODELS = 'z_models',
PLUGINS = 'z_plugins',
PROJECTS = 'z_projects',
PROJECTS_USERS = 'z_projects_users',
RELATIONS = 'z_relations',
SHARED_BASES = 'z_shared_bases',
SHARED_VIEWS = 'z_shared_views',
}
export const orderedMetaTables = [
MetaTable.MODEL_ROLE_VISIBILITY,
MetaTable.PLUGIN,
MetaTable.AUDIT,
MetaTable.TEAM_USERS,
MetaTable.TEAMS,
MetaTable.ORGS,
MetaTable.PROJECT_USERS,
MetaTable.USERS,
MetaTable.KANBAN_VIEW_COLUMNS,
MetaTable.PROJECT_USER,
MetaTable.USER,
MetaTable.KANBAN_VIEW_COLUMN,
MetaTable.KANBAN_VIEW,
MetaTable.GRID_VIEW_COLUMNS,
MetaTable.GRID_VIEW_COLUMN,
MetaTable.GRID_VIEW,
MetaTable.GALLERY_VIEW_COLUMNS,
MetaTable.GALLERY_VIEW_COLUMN,
MetaTable.GALLERY_VIEW,
MetaTable.FORM_VIEW_COLUMNS,
MetaTable.FORM_VIEW_COLUMN,
MetaTable.FORM_VIEW,
MetaTable.SHARED_VIEWS,
MetaTable.SORT,
MetaTable.FILTER_EXP,
MetaTable.HOOK_LOGS,
MetaTable.HOOKS,
MetaTable.VIEWS,
MetaTable.HOOK_LOG,
MetaTable.HOOK,
MetaTable.VIEW,
MetaTable.COL_FORMULA,
MetaTable.COL_ROLLUP,
MetaTable.COL_LOOKUP,
MetaTable.COL_SELECT_OPTIONS,
MetaTable.COL_RELATIONS,
MetaTable.COLUMN_VALIDATIONS,
MetaTable.COLUMNS,
MetaTable.MODELS,
MetaTable.BASES,
MetaTable.COL_SELECT_OPTION,
MetaTable.COL_RELATION,
MetaTable.COLUMN,
MetaTable.MODEL,
MetaTable.BASE,
MetaTable.PROJECT,
];
@ -140,6 +188,7 @@ export enum CacheScope {
INSTANCE_META = 'instanceMeta',
USER_PROJECT = 'userProject',
}
export enum CacheGetType {
TYPE_ARRAY = 'TYPE_ARRAY',
TYPE_OBJECT = 'TYPE_OBJECT',

214
packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts

@ -10,6 +10,7 @@ import Migrator from '../db/sql-migrator/lib/KnexMigrator';
import Noco from '../Noco';
import { Tele } from 'nc-help';
import { MetaTableV1 } from '../utils/globals';
import { GqlApiBuilder } from './gql/GqlApiBuilder';
import { XCEeError } from '../meta/NcMetaMgr';
import { RestApiBuilder } from './rest/RestApiBuilder';
@ -93,7 +94,7 @@ export default class NcProjectBuilder {
this.authHook = await this.app.ncMeta.metaGet(
this.id,
'db',
'nc_hooks',
MetaTableV1.HOOKS,
{
type: 'AUTH_MIDDLEWARE',
}
@ -114,13 +115,18 @@ export default class NcProjectBuilder {
data.req.args
);
this.app.ncMeta.audit(this.id, curBuilder.getDbAlias(), 'nc_audit', {
op_type: 'RELATION',
op_sub_type: 'CREATED',
user: data.user.email,
description: `created relation between tables ${data.req.args.childTable} and ${data.req.args.parentTable} `,
ip: data.ctx.req.clientIp,
});
this.app.ncMeta.audit(
this.id,
curBuilder.getDbAlias(),
MetaTableV1.AUDIT,
{
op_type: 'RELATION',
op_sub_type: 'CREATED',
user: data.user.email,
description: `created relation between tables ${data.req.args.childTable} and ${data.req.args.parentTable} `,
ip: data.ctx.req.clientIp,
}
);
console.log(
`Added new relation between : ${data.req.args.parentTable} ==> ${data.req.args.childTable}`
);
@ -132,13 +138,18 @@ export default class NcProjectBuilder {
data.req.args.childTable,
data.req.args
);
this.app.ncMeta.audit(this.id, curBuilder.getDbAlias(), 'nc_audit', {
op_type: 'RELATION',
op_sub_type: 'DELETED',
user: data.user.email,
description: `deleted relation between tables ${data.req.args.childTable} and ${data.req.args.parentTable} `,
ip: data.ctx.req.clientIp,
});
this.app.ncMeta.audit(
this.id,
curBuilder.getDbAlias(),
MetaTableV1.AUDIT,
{
op_type: 'RELATION',
op_sub_type: 'DELETED',
user: data.user.email,
description: `deleted relation between tables ${data.req.args.childTable} and ${data.req.args.parentTable} `,
ip: data.ctx.req.clientIp,
}
);
console.log(
`Deleted relation between : ${data.req.args.parentTable} ==> ${data.req.args.childTable}`
);
@ -198,62 +209,87 @@ export default class NcProjectBuilder {
case 'tableCreate':
await curBuilder.onTableCreate(data.req.args.tn, data.req.args);
this.app.ncMeta.audit(this.id, curBuilder.getDbAlias(), 'nc_audit', {
op_type: 'TABLE',
op_sub_type: 'CREATED',
user: data.user.email,
description: `created table ${data.req.args.tn} with alias ${data.req.args._tn} `,
ip: data.ctx.req.clientIp,
});
this.app.ncMeta.audit(
this.id,
curBuilder.getDbAlias(),
MetaTableV1.AUDIT,
{
op_type: 'TABLE',
op_sub_type: 'CREATED',
user: data.user.email,
description: `created table ${data.req.args.tn} with alias ${data.req.args._tn} `,
ip: data.ctx.req.clientIp,
}
);
console.log(`Added new routes for table : ${data.req.args.tn}`);
break;
case 'viewCreate':
await curBuilder.onViewCreate(data.req.args.view_name, data.req.args);
this.app.ncMeta.audit(this.id, curBuilder.getDbAlias(), 'nc_audit', {
op_type: 'VIEW',
op_sub_type: 'CREATED',
user: data.user.email,
description: `created view ${data.req.args.view_name} `,
ip: data.ctx.req.clientIp,
});
this.app.ncMeta.audit(
this.id,
curBuilder.getDbAlias(),
MetaTableV1.AUDIT,
{
op_type: 'VIEW',
op_sub_type: 'CREATED',
user: data.user.email,
description: `created view ${data.req.args.view_name} `,
ip: data.ctx.req.clientIp,
}
);
console.log(`Added new routes for table : ${data.req.args.tn}`);
break;
case 'viewUpdate':
await curBuilder.onViewUpdate(data.req.args.view_name);
this.app.ncMeta.audit(this.id, curBuilder.getDbAlias(), 'nc_audit', {
op_type: 'VIEW',
op_sub_type: 'UPDATED',
user: data.user.email,
description: `updated view ${data.req.args.view_name} `,
ip: data.ctx.req.clientIp,
});
this.app.ncMeta.audit(
this.id,
curBuilder.getDbAlias(),
MetaTableV1.AUDIT,
{
op_type: 'VIEW',
op_sub_type: 'UPDATED',
user: data.user.email,
description: `updated view ${data.req.args.view_name} `,
ip: data.ctx.req.clientIp,
}
);
console.log(`Added new routes for table : ${data.req.args.tn}`);
break;
case 'tableDelete':
await curBuilder.onTableDelete(data.req.args.tn);
this.app.ncMeta.audit(this.id, curBuilder.getDbAlias(), 'nc_audit', {
op_type: 'TABLE',
op_sub_type: 'DELETED',
user: data.user.email,
description: `deleted table ${data.req.args.tn} `,
ip: data.ctx.req.clientIp,
});
this.app.ncMeta.audit(
this.id,
curBuilder.getDbAlias(),
MetaTableV1.AUDIT,
{
op_type: 'TABLE',
op_sub_type: 'DELETED',
user: data.user.email,
description: `deleted table ${data.req.args.tn} `,
ip: data.ctx.req.clientIp,
}
);
console.log(`Deleted routes for table : ${data.req.args.tn}`);
break;
case 'tableRename':
await curBuilder.onTableRename(data.req.args.tn_old, data.req.args.tn);
this.app.ncMeta.audit(this.id, curBuilder.getDbAlias(), 'nc_audit', {
op_type: 'TABLE',
op_sub_type: 'RENAMED',
user: data.user.email,
description: `renamed table ${data.req.args.tn_old} to ${data.req.args.tn} `,
ip: data.ctx.req.clientIp,
});
this.app.ncMeta.audit(
this.id,
curBuilder.getDbAlias(),
MetaTableV1.AUDIT,
{
op_type: 'TABLE',
op_sub_type: 'RENAMED',
user: data.user.email,
description: `renamed table ${data.req.args.tn_old} to ${data.req.args.tn} `,
ip: data.ctx.req.clientIp,
}
);
console.log(`Updated routes for table : ${data.req.args.tn}`);
break;
@ -263,13 +299,18 @@ export default class NcProjectBuilder {
data.req.args.tn
);
this.app.ncMeta.audit(this.id, curBuilder.getDbAlias(), 'nc_audit', {
op_type: 'TABLE',
op_sub_type: 'RENAMED',
user: data.user.email,
description: `renamed table alias ${data.req.args.tn_old} to ${data.req.args.tn} `,
ip: data.ctx.req.clientIp,
});
this.app.ncMeta.audit(
this.id,
curBuilder.getDbAlias(),
MetaTableV1.AUDIT,
{
op_type: 'TABLE',
op_sub_type: 'RENAMED',
user: data.user.email,
description: `renamed table alias ${data.req.args.tn_old} to ${data.req.args.tn} `,
ip: data.ctx.req.clientIp,
}
);
console.log(`Updated routes for table : ${data.req.args.tn}`);
break;
@ -320,13 +361,18 @@ export default class NcProjectBuilder {
case 'tableUpdate':
await curBuilder.onTableUpdate(data.req.args);
this.app.ncMeta.audit(this.id, curBuilder.getDbAlias(), 'nc_audit', {
op_type: 'TABLE',
op_sub_type: 'UPDATED',
user: data.user.email,
description: `updated table ${data.req.args.tn} with alias ${data.req.args._tn} `,
ip: data.ctx.req.clientIp,
});
this.app.ncMeta.audit(
this.id,
curBuilder.getDbAlias(),
MetaTableV1.AUDIT,
{
op_type: 'TABLE',
op_sub_type: 'UPDATED',
user: data.user.email,
description: `updated table ${data.req.args.tn} with alias ${data.req.args._tn} `,
ip: data.ctx.req.clientIp,
}
);
console.log(`Updated validations for table : ${data.req.args.tn}`);
break;
@ -420,13 +466,18 @@ export default class NcProjectBuilder {
break;
case 'viewDelete':
await curBuilder.onViewDelete(data.req.args.view_name);
this.app.ncMeta.audit(this.id, curBuilder.getDbAlias(), 'nc_audit', {
op_type: 'VIEW',
op_sub_type: 'DELETED',
user: data.user.email,
description: `deleted view ${data.req.args.view_name} `,
ip: data.ctx.req.clientIp,
});
this.app.ncMeta.audit(
this.id,
curBuilder.getDbAlias(),
MetaTableV1.AUDIT,
{
op_type: 'VIEW',
op_sub_type: 'DELETED',
user: data.user.email,
description: `deleted view ${data.req.args.view_name} `,
ip: data.ctx.req.clientIp,
}
);
break;
case 'tableMetaRecreate':
@ -482,7 +533,7 @@ export default class NcProjectBuilder {
this.apiBuilders.splice(0, this.apiBuilders.length);
await this.app.ncMeta.projectStatusUpdate(this.id, 'stopped');
NcProjectBuilder.triggerGarbageCollect();
this.app.ncMeta.audit(this.id, null, 'nc_audit', {
this.app.ncMeta.audit(this.id, null, MetaTableV1.AUDIT, {
op_type: 'PROJECT',
op_sub_type: 'STOPPED',
user: data.user.email,
@ -493,7 +544,7 @@ export default class NcProjectBuilder {
case 'projectStart':
await this.init();
this.app.ncMeta.audit(this.id, null, 'nc_audit', {
this.app.ncMeta.audit(this.id, null, MetaTableV1.AUDIT, {
op_type: 'PROJECT',
op_sub_type: 'STARTED',
user: data.user.email,
@ -507,7 +558,7 @@ export default class NcProjectBuilder {
this.apiBuilders.splice(0, this.apiBuilders.length);
await this.app.ncMeta.projectDeleteById(this.id);
await this.app.ncMeta
.knex('nc_projects_users')
.knex(MetaTableV1.PROJECTS_USERS)
.where({ project_id: this.id })
.del();
for (const db of this.config?.envs?.[this.appConfig?.workingEnv]?.db ||
@ -517,7 +568,7 @@ export default class NcProjectBuilder {
await this.app.ncMeta.metaReset(this.id, dbAlias, apiType);
}
NcProjectBuilder.triggerGarbageCollect();
this.app.ncMeta.audit(this.id, null, 'nc_audit', {
this.app.ncMeta.audit(this.id, null, MetaTableV1.AUDIT, {
op_type: 'PROJECT',
op_sub_type: 'DELETED',
user: data.user.email,
@ -530,7 +581,7 @@ export default class NcProjectBuilder {
case 'xcMetaTablesImportZipToLocalFsAndDb':
case 'projectRestart':
await this.reInit();
this.app.ncMeta.audit(this.id, null, 'nc_audit', {
this.app.ncMeta.audit(this.id, null, MetaTableV1.AUDIT, {
op_type: 'PROJECT',
op_sub_type: 'RESTARTED',
user: data.user.email,
@ -844,9 +895,14 @@ export default class NcProjectBuilder {
}
protected async addAuthHookToMiddleware(): Promise<any> {
this.authHook = await this.app.ncMeta.metaGet(this.id, 'db', 'nc_hooks', {
type: 'AUTH_MIDDLEWARE',
});
this.authHook = await this.app.ncMeta.metaGet(
this.id,
'db',
MetaTableV1.HOOKS,
{
type: 'AUTH_MIDDLEWARE',
}
);
this.router.use(async (req: any, _res, next) => {
if (this.authHook && this.authHook.url) {

83
packages/nocodb/src/lib/v1-legacy/gql/GqlApiBuilder.ts

@ -1,8 +1,8 @@
import DataLoader from 'dataloader';
import debug from 'debug';
import { Router } from 'express';
import { execute } from 'graphql';
import { GraphQLJSON } from 'graphql-type-json';
// import { execute } from 'graphql';
// import { GraphQLJSON } from 'graphql-type-json';
import _ from 'lodash';
import { BaseType } from 'xc-core-ts';
@ -11,6 +11,7 @@ import { DbConfig, NcConfig } from '../../../interface/config';
import ExpressXcTsPolicyGql from '../../db/sql-mgr/code/gql-policies/xc-ts/ExpressXcTsPolicyGql';
import GqlXcSchemaFactory from '../../db/sql-mgr/code/gql-schema/xc-ts/GqlXcSchemaFactory';
import ModelXcMetaFactory from '../../db/sql-mgr/code/models/xc/ModelXcMetaFactory';
import { MetaTableV1 } from '../../utils/globals';
import NcHelp from '../../utils/NcHelp';
import NcProjectBuilder from '../NcProjectBuilder';
import Noco from '../../Noco';
@ -19,11 +20,11 @@ import BaseApiBuilder, {
} from '../../utils/common/BaseApiBuilder';
import NcMetaIO from '../../meta/NcMetaIO';
import { m2mNotChildren, m2mNotChildrenCount } from './GqlCommonResolvers';
// import { m2mNotChildren, m2mNotChildrenCount } from './GqlCommonResolvers';
import GqlMiddleware from './GqlMiddleware';
import { GqlProcedureResolver } from './GqlProcedureResolver';
import GqlResolver from './GqlResolver';
import commonSchema from './common.schema';
// import commonSchema from './common.schema';
const log = debug('nc:api:gql');
@ -2573,11 +2574,16 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
);
await this.generateAndSaveAcl(functionObj.function_name, 'function');
await this.xcMeta.metaInsert(this.projectId, this.dbAlias, 'nc_models', {
title: functionObj.function_name,
meta: JSON.stringify({ ...functionObj, type: 'function' }),
type: 'function',
});
await this.xcMeta.metaInsert(
this.projectId,
this.dbAlias,
MetaTableV1.MODELS,
{
title: functionObj.function_name,
meta: JSON.stringify({ ...functionObj, type: 'function' }),
type: 'function',
}
);
}
this.generateAndSaveAcl(functionName, 'function');
@ -2591,10 +2597,15 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
this.log(`onFunctionCreate : Deleting '%s' function meta`, functionName);
await this.xcMeta.metaDelete(this.projectId, this.dbAlias, 'nc_models', {
title: functionName,
type: 'function',
});
await this.xcMeta.metaDelete(
this.projectId,
this.dbAlias,
MetaTableV1.MODELS,
{
title: functionName,
type: 'function',
}
);
this.resolvers.___procedure.functionDelete(functionName);
this.schemas.___procedure = this.resolvers.___procedure.getSchema();
@ -2617,11 +2628,16 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
);
await this.generateAndSaveAcl(procedureObj.procedure_name, 'procedure');
await this.xcMeta.metaInsert(this.projectId, this.dbAlias, 'nc_models', {
title: procedureObj.procedure_name,
meta: JSON.stringify({ ...procedureObj, type: 'procedure' }),
type: 'procedure',
});
await this.xcMeta.metaInsert(
this.projectId,
this.dbAlias,
MetaTableV1.MODELS,
{
title: procedureObj.procedure_name,
meta: JSON.stringify({ ...procedureObj, type: 'procedure' }),
type: 'procedure',
}
);
}
this.generateAndSaveAcl(procedureName, 'procedure');
@ -2634,10 +2650,15 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
this.log(`onProcedureDelete : '%s'`, procedureName);
this.log(`onProcedureDelete : Deleting '%s' function meta`, procedureName);
await this.xcMeta.metaDelete(this.projectId, this.dbAlias, 'nc_models', {
title: procedureName,
type: 'procedure',
});
await this.xcMeta.metaDelete(
this.projectId,
this.dbAlias,
MetaTableV1.MODELS,
{
title: procedureName,
type: 'procedure',
}
);
this.resolvers.___procedure.procedureDelete(procedureName);
this.schemas.___procedure = this.resolvers.___procedure.getSchema();
@ -2659,7 +2680,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
}
private async initGraphqlRoute(): Promise<void> {
this.log(`initGraphqlRoute : Initializing graphql router endpoint`);
/* this.log(`initGraphqlRoute : Initializing graphql router endpoint`);
try {
const { mergeResolvers, mergeTypeDefs } = await import(
'@graphql-tools/merge'
@ -2727,7 +2748,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
this.resolversCount = Object.keys(rootValue).length;
} catch (e) {
console.log(e);
}
}*/
}
private generateLoaderFromStringBody(fnBody: string[]): any {
@ -2784,7 +2805,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
schema: this.schemas[tn],
},
@ -2873,7 +2894,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
schema: this.schemas[tn],
},
@ -2890,7 +2911,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
const models = await this.xcMeta.metaList(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
fields: ['meta'],
condition: {
@ -2928,7 +2949,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
schema,
},
@ -2971,7 +2992,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
schema,
},
@ -2988,7 +3009,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
await this.xcMeta.metaInsert(
this.projectId,
this.dbAlias,
'nc_loaders',
MetaTableV1.MODELS,
{
title: `${mm.tn}Mm${mm.rtn}List`,
parent: mm.tn,
@ -3058,7 +3079,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
schema: this.schemas[tn],
// schema_previous: JSON.stringify(previousSchemas)

14
packages/nocodb/src/lib/v1-legacy/plugins/NcPluginMgr.ts

@ -29,6 +29,7 @@ import VultrPluginConfig from '../../plugins/vultr';
import SESPluginConfig from '../../plugins/ses';
import Noco from '../../Noco';
import NcMetaIO from '../../meta/NcMetaIO';
import { MetaTableV1 } from '../../utils/globals';
import Local from './adapters/storage/Local';
@ -70,12 +71,17 @@ class NcPluginMgr {
public async init(): Promise<void> {
/* Populate rows into nc_plugins table if not present */
for (const plugin of defaultPlugins) {
const pluginConfig = await this.ncMeta.metaGet(null, null, 'nc_plugins', {
title: plugin.title,
});
const pluginConfig = await this.ncMeta.metaGet(
null,
null,
MetaTableV1.PLUGINS,
{
title: plugin.title,
}
);
if (!pluginConfig) {
await this.ncMeta.metaInsert(null, null, 'nc_plugins', {
await this.ncMeta.metaInsert(null, null, MetaTableV1.PLUGINS, {
title: plugin.title,
version: plugin.version,
logo: plugin.logo,

116
packages/nocodb/src/lib/v1-legacy/rest/RestApiBuilder.ts

@ -37,7 +37,7 @@ import Column from '../../models/Column';
// import NocoResolverGenerator from '../v1-legacy-resolver/NocoResolverGenerator';
// import { RestCtrlv2 } from './RestCtrlv2';
// import registerRestCtrl from './registerRestCtrl';
import { MetaTable } from '../../utils/globals';
import { MetaTable, MetaTableV1 } from '../../utils/globals';
// import { BaseModelSqlv2 } from '../../sql-data-mapper/lib/sql/BaseModelSqlv2';
const log = debug('nc:api:rest');
@ -554,7 +554,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
!(await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{ title: table.tn }
))
) {
@ -566,7 +566,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaInsert(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
order: table.order || ++order,
view_order: 1,
@ -580,7 +580,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
const { id: modelId } = await this.xcMeta.metaInsert2(
this.projectId,
this.dbAlias,
MetaTable.MODELS,
MetaTable.MODEL,
{
tn: table.tn,
_tn: meta._tn,
@ -686,7 +686,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
title: table.tn,
alias: meta._tn,
@ -1387,7 +1387,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
const existingModel = await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{ title: oldTablename }
);
@ -1405,7 +1405,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
title: newTablename,
meta: JSON.stringify(meta),
@ -1428,7 +1428,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_acl',
MetaTableV1.MODELS,
{
tn: newTablename,
},
@ -1652,7 +1652,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
const rExistingModel = await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{ title: relationTable }
);
@ -1677,7 +1677,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
meta: JSON.stringify(oldMeta),
},
@ -1856,7 +1856,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
const existingModel = await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{ title: tnp }
);
let queryParams;
@ -1904,7 +1904,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
meta: JSON.stringify(oldMeta),
...(queryParams
@ -1999,7 +1999,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
const existingModel = await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{ title: tnc }
);
@ -2047,7 +2047,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
meta: JSON.stringify(oldMeta),
...(queryParams
@ -2144,7 +2144,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
const existingModel = await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{ title: tnp }
);
const tagName = `${tnp}HasMany${tnc}`;
@ -2171,7 +2171,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
title: tnp,
meta: JSON.stringify(oldMeta),
@ -2210,7 +2210,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
const existingModel = await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{ title: tnc }
);
const tagName = `${tnc}BelongsTo${tnp}`;
@ -2236,7 +2236,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
title: tnc,
meta: JSON.stringify(oldMeta),
@ -2356,11 +2356,16 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
functionName
);
await this.generateAndSaveAcl(functionObj.function_name, 'function');
await this.xcMeta.metaInsert(this.projectId, this.dbAlias, 'nc_models', {
title: functionObj.function_name,
meta: JSON.stringify({ ...functionObj, type: 'function' }),
type: 'function',
});
await this.xcMeta.metaInsert(
this.projectId,
this.dbAlias,
MetaTableV1.MODELS,
{
title: functionObj.function_name,
meta: JSON.stringify({ ...functionObj, type: 'function' }),
type: 'function',
}
);
}
this.generateAndSaveAcl(functionName, 'function');
@ -2376,10 +2381,15 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
public async onFunctionDelete(functionName: string): Promise<void> {
this.log(`onFunctionDelete : '%s'`, functionName);
this.log(`onFunctionDelete : Delete meta of '%s' function`, functionName);
await this.xcMeta.metaDelete(this.projectId, this.dbAlias, 'nc_models', {
title: functionName,
type: 'function',
});
await this.xcMeta.metaDelete(
this.projectId,
this.dbAlias,
MetaTableV1.MODELS,
{
title: functionName,
type: 'function',
}
);
this.log(`onFunctionDelete : Update function and procedure routes`);
this.procedureCtrl.functionDelete(functionName);
this.routers.___procedure.stack.splice(
@ -2411,11 +2421,16 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
procedureName
);
await this.generateAndSaveAcl(procedureObj.procedure_name, 'procedure');
await this.xcMeta.metaInsert(this.projectId, this.dbAlias, 'nc_models', {
title: procedureObj.procedure_name,
meta: JSON.stringify({ ...procedureObj, type: 'procedure' }),
type: 'procedure',
});
await this.xcMeta.metaInsert(
this.projectId,
this.dbAlias,
MetaTableV1.MODELS,
{
title: procedureObj.procedure_name,
meta: JSON.stringify({ ...procedureObj, type: 'procedure' }),
type: 'procedure',
}
);
}
this.generateAndSaveAcl(procedureName, 'procedure');
@ -2431,10 +2446,15 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
public async onProcedureDelete(procedureName: string): Promise<void> {
this.log(`onProcedureDelete : '%s'`, procedureName);
this.log(`onProcedureDelete : Delete meta of '%s' function`, procedureName);
await this.xcMeta.metaDelete(this.projectId, this.dbAlias, 'nc_models', {
title: procedureName,
type: 'procedure',
});
await this.xcMeta.metaDelete(
this.projectId,
this.dbAlias,
MetaTableV1.MODELS,
{
title: procedureName,
type: 'procedure',
}
);
this.log(`onProcedureDelete : Update function and procedure routes`);
this.procedureCtrl.procedureDelete(procedureName);
this.routers.___procedure.stack.splice(
@ -2451,7 +2471,11 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
public async onSwaggerDocUpdate(tn: any): Promise<void> {
this.log(`onSwaggerDocUpdate : '%s'`, tn);
const swaggerDocs = (
await this.xcMeta.metaList(this.projectId, this.dbAlias, 'nc_models')
await this.xcMeta.metaList(
this.projectId,
this.dbAlias,
MetaTableV1.MODELS
)
)
.filter((m) => m.schema)
.map((m) => JSON.parse(m.schema));
@ -2485,7 +2509,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
const meta = await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
title: changeObj.tn,
type: 'table',
@ -2503,7 +2527,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
schema: JSON.stringify(oldSwaggerDoc),
// schema_previous: JSON.stringify(previousSchemas)
@ -2562,7 +2586,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaInsert(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
title: functionObj.function_name,
meta: JSON.stringify({ ...functionObj, type: 'function' }),
@ -2581,7 +2605,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaInsert(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
title: procedureObj.procedure_name,
meta: JSON.stringify({ ...procedureObj, type: 'procedure' }),
@ -2830,7 +2854,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
schema: JSON.stringify(swaggerDoc),
},
@ -2942,7 +2966,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
const meta = await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
title: tn,
type: 'table',
@ -2960,7 +2984,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
schema: JSON.stringify(oldSwaggerDoc),
// schema_previous: JSON.stringify(previousSchemas)
@ -2998,7 +3022,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
const meta = await this.xcMeta.metaGet(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
title: metaObj.tn,
type: 'table',
@ -3016,7 +3040,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
MetaTableV1.MODELS,
{
schema: JSON.stringify(oldSwaggerDoc),
// schema_previous: JSON.stringify(previousSchemas)

77
packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrl.ts

@ -30,6 +30,7 @@ import axios from 'axios';
import IEmailAdapter from '../../../interface/IEmailAdapter';
import { Tele } from 'nc-help';
import { MetaTable, MetaTableV1 } from '../../utils/globals'
import XcCache from '../plugins/adapters/cache/XcCache';
passport.serializeUser(function (
@ -72,7 +73,7 @@ passport.deserializeUser(function (user, done) {
});
const NC_ROLES = 'nc_roles';
const NC_ACL = 'nc_acl';
const NC_ACL = MetaTableV1.ACL;
export default class RestAuthCtrl {
protected app: Noco;
@ -350,9 +351,14 @@ export default class RestAuthCtrl {
)
);
const googlePlugin = await this.xcMeta.metaGet(null, null, 'nc_plugins', {
title: 'Google',
});
const googlePlugin = await this.xcMeta.metaGet(
null,
null,
MetaTableV1.PLUGINS,
{
title: 'Google',
}
);
if (googlePlugin && googlePlugin.input) {
const settings = JSON.parse(googlePlugin.input);
@ -456,9 +462,14 @@ export default class RestAuthCtrl {
passport.use(googleStrategy);
}
const githubPlugin = await this.xcMeta.metaGet(null, null, 'nc_plugins', {
title: 'Github',
});
const githubPlugin = await this.xcMeta.metaGet(
null,
null,
MetaTableV1.PLUGINS,
{
title: 'Github',
}
);
if (githubPlugin && githubPlugin.input) {
const settings = JSON.parse(githubPlugin.input);
process.env.NC_GITHUB_CLIENT_ID = settings.client_id;
@ -611,7 +622,7 @@ export default class RestAuthCtrl {
if (!sharedBase) {
sharedBase = await this.xcMeta
.knex('nc_shared_bases')
.knex(MetaTableV1.SHARED_BASES)
.where({
enabled: true,
shared_base_id: req.headers['xc-shared-base-id'],
@ -660,7 +671,7 @@ export default class RestAuthCtrl {
this.setTokenCookie(res, refreshToken);
this.xcMeta.audit(null, null, 'nc_audit', {
this.xcMeta.audit(null, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'SIGNIN',
user: user.email,
@ -719,7 +730,7 @@ export default class RestAuthCtrl {
this.setTokenCookie(res, refreshToken);
this.xcMeta.audit(null, null, 'nc_audit', {
this.xcMeta.audit(null, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'SIGNIN',
user: user.email,
@ -975,7 +986,7 @@ export default class RestAuthCtrl {
user = (req as any).user;
this.xcMeta.audit(null, null, 'nc_audit', {
this.xcMeta.audit(null, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'SIGNUP',
user: user.email,
@ -1059,7 +1070,7 @@ export default class RestAuthCtrl {
}
console.log(`Password reset token : ${token}`);
this.xcMeta.audit(null, null, 'nc_audit', {
this.xcMeta.audit(null, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'PASSWORD_FORGOT',
user: user.email,
@ -1113,7 +1124,7 @@ export default class RestAuthCtrl {
id: user.id,
});
this.xcMeta.audit(null, null, 'nc_audit', {
this.xcMeta.audit(null, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'PASSWORD_RESET',
user: user.email,
@ -1149,7 +1160,7 @@ export default class RestAuthCtrl {
})
.where({ id: user.id });
this.xcMeta.audit(null, null, 'nc_audit', {
this.xcMeta.audit(null, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'PASSWORD_CHANGE',
user: user.email,
@ -1177,7 +1188,7 @@ export default class RestAuthCtrl {
})
.where({ id: user.id });
this.xcMeta.audit(null, null, 'nc_audit', {
this.xcMeta.audit(null, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'EMAIL_VERIFICATION',
user: user.email,
@ -1281,7 +1292,7 @@ export default class RestAuthCtrl {
}
Tele.emit('evt', { evt_type: 'project:invite', count: count?.count });
this.xcMeta.audit(req.body.project_id, null, 'nc_audit', {
this.xcMeta.audit(req.body.project_id, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'INVITE',
user: req.user.email,
@ -1334,7 +1345,7 @@ export default class RestAuthCtrl {
await this.xcMeta.metaUpdate(
req?.body?.project_id,
null,
'nc_projects_users',
MetaTableV1.PROJECTS_USERS,
{
roles: 'creator',
},
@ -1343,7 +1354,7 @@ export default class RestAuthCtrl {
}
);
this.xcMeta.audit(null, null, 'nc_audit', {
this.xcMeta.audit(null, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'ROLES_MANAGEMENT',
user: req.user.email,
@ -1404,8 +1415,8 @@ export default class RestAuthCtrl {
const queryBuilder = this.users
.select(
'xc_users.*',
'nc_projects_users.project_id',
'nc_projects_users.roles as roles'
`${MetaTableV1.PROJECTS_USERS}.project_id`,
`${MetaTableV1.PROJECTS_USERS}.roles as roles`
)
.offset(offset)
.limit(limit);
@ -1414,16 +1425,24 @@ export default class RestAuthCtrl {
queryBuilder.where('email', 'like', `%${query}%`);
}
const self = this;
queryBuilder.leftJoin('nc_projects_users', function () {
this.on('nc_projects_users.user_id', '=', 'xc_users.id').andOn(
'nc_projects_users.project_id',
queryBuilder.leftJoin(MetaTableV1.PROJECTS_USERS, function () {
this.on(
`${MetaTableV1.PROJECTS_USERS}.user_id`,
'=',
'xc_users.id'
).andOn(
`${MetaTableV1.PROJECTS_USERS}.project_id`,
'=',
self.xcMeta.knex.raw('?', [project_id])
);
});
if (!req.session?.passport?.user?.roles?.owner) {
queryBuilder.whereNot('nc_projects_users.roles', 'like', '%owner%');
queryBuilder.whereNot(
`${MetaTableV1.PROJECTS_USERS}.roles`,
'like',
'%owner%'
);
count = (
await this.users
.count('id as count')
@ -1474,7 +1493,7 @@ export default class RestAuthCtrl {
});
await this.sendInviteEmail(user.email, invite_token, req);
this.xcMeta.audit(null, null, 'nc_audit', {
this.xcMeta.audit(null, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'RESEND_INVITE',
user: user.email,
@ -1624,7 +1643,7 @@ export default class RestAuthCtrl {
}
}
this.xcMeta.audit(null, null, 'nc_audit', {
this.xcMeta.audit(null, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'ROLES_MANAGEMENT',
user: req.user.email,
@ -1750,6 +1769,10 @@ export default class RestAuthCtrl {
}
public async loadLatestApiTokens(): Promise<any> {
this.apiTokens = await this.xcMeta.metaList(null, null, 'nc_api_tokens');
this.apiTokens = await this.xcMeta.metaList(
null,
null,
MetaTable.API_TOKEN
);
}
}

11
packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrlEE.ts

@ -3,6 +3,7 @@ import { Strategy } from 'passport-jwt';
import { v4 as uuidv4 } from 'uuid';
import validator from 'validator';
import { Tele } from 'nc-help';
import { MetaTableV1 } from '../../utils/globals';
import XcCache from '../plugins/adapters/cache/XcCache';
@ -59,7 +60,7 @@ export default class RestAuthCtrlEE extends RestAuthCtrl {
'editor'
);
}
this.xcMeta.audit(req.body.project_id, null, 'nc_audit', {
this.xcMeta.audit(req.body.project_id, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'INVITE',
user: req.user.email,
@ -87,7 +88,7 @@ export default class RestAuthCtrlEE extends RestAuthCtrl {
Tele.emit('evt', { evt_type: 'project:invite', count: count?.count });
this.xcMeta.audit(req.body.project_id, null, 'nc_audit', {
this.xcMeta.audit(req.body.project_id, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'INVITE',
user: req.user.email,
@ -165,7 +166,7 @@ export default class RestAuthCtrlEE extends RestAuthCtrl {
await this.xcMeta.metaUpdate(
req?.body?.project_id,
null,
'nc_projects_users',
MetaTableV1.PROJECTS_USERS,
{
roles: req.body.roles,
},
@ -177,7 +178,7 @@ export default class RestAuthCtrlEE extends RestAuthCtrl {
XcCache.del(`${req.body.email}___${req?.body?.project_id}`);
this.xcMeta.audit(null, null, 'nc_audit', {
this.xcMeta.audit(null, null, MetaTableV1.AUDIT, {
op_type: 'AUTHENTICATION',
op_sub_type: 'ROLES_MANAGEMENT',
user: req.user.email,
@ -219,7 +220,7 @@ export default class RestAuthCtrlEE extends RestAuthCtrl {
.then((user) => {
if (req.ncProjectId) {
this.xcMeta
.metaGet(req.ncProjectId, null, 'nc_projects_users', {
.metaGet(req.ncProjectId, null, MetaTableV1.PROJECTS_USERS, {
user_id: user?.id,
})
.then((projectUser) => {

23
packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts

@ -3,11 +3,12 @@ import { NcConfig } from '../../interface/config';
import debug from 'debug';
import NcMetaIO from '../meta/NcMetaIO';
import { Tele } from 'nc-help';
import ncProjectEnvUpgrader from './ncProjectEnvUpgrader';
import ncProjectEnvUpgrader0011045 from './ncProjectEnvUpgrader0011045';
import ncProjectUpgraderV2_0090000 from './ncProjectUpgraderV2_0090000';
import ncDataTypesUpgrader from './ncDataTypesUpgrader';
import ncProjectRolesUpgrader from './ncProjectRolesUpgrader';
import { MetaTable } from '../utils/globals'
import ncProjectEnvUpgrader from './handlers/nc_0011043_project_env_upgrader';
import ncProjectEnvUpgrader2 from './handlers/nc_0011045_project_env_upgrader';
import ncProjectV2Upgrader from './handlers/nc_0090000_project_v2_upgrader';
import ncDataTypesUpgrader from './handlers/nc_0098004_data_types_upgrader';
import ncProjectRolesUpgrader from './handlers/nc_0098005_project_roles_upgrader';
const log = debug('nc:version-upgrader');
import boxen from 'boxen';
@ -31,17 +32,17 @@ export default class NcUpgrader {
{ name: '0009000', handler: null },
{ name: '0009044', handler: null },
{ name: '0011043', handler: ncProjectEnvUpgrader },
{ name: '0011045', handler: ncProjectEnvUpgrader0011045 },
{ name: '0090000', handler: ncProjectUpgraderV2_0090000 },
{ name: '0011045', handler: ncProjectEnvUpgrader2 },
{ name: '0090000', handler: ncProjectV2Upgrader },
{ name: '0098004', handler: ncDataTypesUpgrader },
{ name: '0098005', handler: ncProjectRolesUpgrader },
];
if (!(await ctx.ncMeta.knexConnection?.schema?.hasTable?.('nc_store'))) {
if (!(await ctx.ncMeta.knexConnection?.schema?.hasTable?.(MetaTable.STORE))) {
return;
}
this.log(`upgrade : Getting configuration from meta database`);
const config = await ctx.ncMeta.metaGet('', '', 'nc_store', {
const config = await ctx.ncMeta.metaGet('', '', MetaTable.STORE, {
key: this.STORE_KEY,
});
@ -64,7 +65,7 @@ export default class NcUpgrader {
await ctx.ncMeta.metaUpdate(
'',
'',
'nc_store',
MetaTable.STORE,
{
value: JSON.stringify(config),
},
@ -86,7 +87,7 @@ export default class NcUpgrader {
const configObj: any = {};
const isOld = (await ctx.ncMeta.projectList())?.length;
configObj.version = isOld ? '0009000' : process.env.NC_VERSION;
await ctx.ncMeta.metaInsert('', '', 'nc_store', {
await ctx.ncMeta.metaInsert('', '', MetaTable.STORE, {
key: NcUpgrader.STORE_KEY,
value: JSON.stringify(configObj),
});

2
packages/nocodb/src/lib/version-upgrader/ncProjectEnvUpgrader.ts → packages/nocodb/src/lib/version-upgrader/handlers/nc_0011043_project_env_upgrader.ts

@ -1,4 +1,4 @@
import { NcUpgraderCtx } from './NcUpgrader';
import { NcUpgraderCtx } from '../NcUpgrader';
export default async function (ctx: NcUpgraderCtx) {
const projects = await ctx.ncMeta.projectList();

2
packages/nocodb/src/lib/version-upgrader/ncProjectEnvUpgrader0011045.ts → packages/nocodb/src/lib/version-upgrader/handlers/nc_0011045_project_env_upgrader.ts

@ -1,4 +1,4 @@
import { NcUpgraderCtx } from './NcUpgrader';
import { NcUpgraderCtx } from '../NcUpgrader';
export default async function (ctx: NcUpgraderCtx) {
const projects = await ctx.ncMeta.projectList();

80
packages/nocodb/src/lib/version-upgrader/ncProjectUpgraderV2_0090000.ts → packages/nocodb/src/lib/version-upgrader/handlers/nc_0090000_project_v2_upgrader.ts

@ -1,9 +1,9 @@
import { NcUpgraderCtx } from './NcUpgrader';
import Noco from '../Noco';
import User from '../models/User';
import Project from '../models/Project';
import ProjectUser from '../models/ProjectUser';
import Model from '../models/Model';
import { NcUpgraderCtx } from '../NcUpgrader';
import Noco from '../../Noco';
import User from '../../models/User';
import Project from '../../models/Project';
import ProjectUser from '../../models/ProjectUser';
import Model from '../../models/Model';
import {
ModelTypes,
substituteColumnAliasWithIdInFormula,
@ -11,25 +11,25 @@ import {
ViewType,
ViewTypes,
} from 'nocodb-sdk';
import Column from '../models/Column';
import LinkToAnotherRecordColumn from '../models/LinkToAnotherRecordColumn';
import NcHelp from '../utils/NcHelp';
import RollupColumn from '../models/RollupColumn';
import View from '../models/View';
import GridView from '../models/GridView';
import KanbanView from '../models/KanbanView';
import FormView from '../models/FormView';
import GalleryView from '../models/GalleryView';
import Sort from '../models/Sort';
import Filter from '../models/Filter';
import ModelRoleVisibility from '../models/ModelRoleVisibility';
import { MetaTable } from '../utils/globals';
import Hook from '../models/Hook';
import FormViewColumn from '../models/FormViewColumn';
import GridViewColumn from '../models/GridViewColumn';
import { getUniqueColumnAliasName } from '../meta/helpers/getUniqueName';
import NcProjectBuilderEE from '../v1-legacy/NcProjectBuilderEE';
import Audit from '../models/Audit';
import Column from '../../models/Column';
import LinkToAnotherRecordColumn from '../../models/LinkToAnotherRecordColumn';
import NcHelp from '../../utils/NcHelp';
import RollupColumn from '../../models/RollupColumn';
import View from '../../models/View';
import GridView from '../../models/GridView';
import KanbanView from '../../models/KanbanView';
import FormView from '../../models/FormView';
import GalleryView from '../../models/GalleryView';
import Sort from '../../models/Sort';
import Filter from '../../models/Filter';
import ModelRoleVisibility from '../../models/ModelRoleVisibility';
import { MetaTable, MetaTableV1 } from '../../utils/globals';
import Hook from '../../models/Hook';
import FormViewColumn from '../../models/FormViewColumn';
import GridViewColumn from '../../models/GridViewColumn';
import { getUniqueColumnAliasName } from '../../meta/helpers/getUniqueName';
import NcProjectBuilderEE from '../../v1-legacy/NcProjectBuilderEE';
import Audit from '../../models/Audit';
export default async function (ctx: NcUpgraderCtx) {
const ncMeta = ctx.ncMeta;
@ -112,7 +112,11 @@ async function migrateProjectUsers(
usersObj: { [p: string]: User },
ncMeta = Noco.ncMeta
) {
const projectUsers = await ncMeta.metaList(null, null, 'nc_projects_users');
const projectUsers = await ncMeta.metaList(
null,
null,
MetaTableV1.PROJECTS_USERS
);
for (const projectUser of projectUsers) {
// skip if project is missing
@ -355,12 +359,16 @@ async function migrateProjectModels(
): Promise<MigrateCtxV1> {
// @ts-ignore
const metas: ModelMetav1[] = await ncMeta.metaList(null, null, 'nc_models');
const metas: ModelMetav1[] = await ncMeta.metaList(
null,
null,
MetaTableV1.MODELS
);
// @ts-ignore
const relations: Relationv1[] = await ncMeta.metaList(
null,
null,
'nc_relations'
MetaTableV1.RELATIONS
);
const models: Model[] = [];
@ -1084,7 +1092,7 @@ async function migrateUIAcl(ctx: MigrateCtxV1, ncMeta: any) {
project_id: string;
created_at?;
updated_at?;
}> = await ncMeta.metaList(null, null, 'nc_disabled_models_for_role');
}> = await ncMeta.metaList(null, null, MetaTableV1.DISABLED_MODELS_FOR_ROLE);
for (const acl of uiAclList) {
// if missing model name skip the view acl migration
@ -1132,7 +1140,7 @@ async function migrateSharedViews(ctx: MigrateCtxV1, ncMeta: any) {
password: string;
view_name: string;
project_id: string;
}> = await ncMeta.metaList(null, null, 'nc_shared_views');
}> = await ncMeta.metaList(null, null, MetaTableV1.SHARED_VIEWS);
for (const sharedView of sharedViews) {
let fk_view_id;
@ -1181,7 +1189,7 @@ async function migrateSharedBase(ncMeta: any) {
enabled: boolean;
project_id: string;
password: string;
}> = await ncMeta.metaList(null, null, 'nc_shared_bases');
}> = await ncMeta.metaList(null, null, MetaTableV1.SHARED_BASES);
for (const sharedBase of sharedBases) {
await Project.update(
@ -1197,7 +1205,11 @@ async function migrateSharedBase(ncMeta: any) {
}
async function migratePlugins(ncMeta: any) {
const plugins: Array<any> = await ncMeta.metaList(null, null, 'nc_plugins');
const plugins: Array<any> = await ncMeta.metaList(
null,
null,
MetaTableV1.PLUGINS
);
for (const plugin of plugins) {
await ncMeta.metaInsert2(null, null, MetaTable.PLUGIN, {
@ -1245,7 +1257,7 @@ async function migrateWebhooks(ctx: MigrateCtxV1, ncMeta: any) {
active: boolean;
created_at?;
updated_at?;
}> = await ncMeta.metaList(null, null, 'nc_hooks');
}> = await ncMeta.metaList(null, null, MetaTableV1.HOOKS);
for (const hookMeta of hooks) {
if (
@ -1327,7 +1339,7 @@ async function migrateAutitLog(
details: string;
created_at: any;
updated_at: any;
}> = await ncMeta.metaList(null, null, 'nc_audit');
}> = await ncMeta.metaList(null, null, MetaTableV1.AUDIT);
for (const audit of audits) {
// skip deleted projects audit

6
packages/nocodb/src/lib/version-upgrader/ncDataTypesUpgrader.ts → packages/nocodb/src/lib/version-upgrader/handlers/nc_0098004_data_types_upgrader.ts

@ -1,6 +1,6 @@
import { UITypes } from 'nocodb-sdk';
import { MetaTable } from '../utils/globals';
import { NcUpgraderCtx } from './NcUpgrader';
import { MetaTable } from '../../utils/globals';
import { NcUpgraderCtx } from '../NcUpgrader';
// The Count and AutoNumber types are removed
// so convert all existing Count and AutoNumber fields to Number type
@ -10,5 +10,5 @@ export default async function (ctx: NcUpgraderCtx) {
.update({ uidt: UITypes.Number })
.where({ uidt: UITypes.Count })
.orWhere({ uidt: UITypes.AutoNumber })
.table(MetaTable.COLUMNS);
.table(MetaTable.COLUMN);
}

12
packages/nocodb/src/lib/version-upgrader/ncProjectRolesUpgrader.ts → packages/nocodb/src/lib/version-upgrader/handlers/nc_0098005_project_roles_upgrader.ts

@ -1,12 +1,12 @@
import { OrgUserRoles } from 'nocodb-sdk';
import { NC_APP_SETTINGS } from '../constants';
import Store from '../models/Store';
import { MetaTable } from '../utils/globals';
import { NcUpgraderCtx } from './NcUpgrader';
import { NC_APP_SETTINGS } from '../../constants';
import Store from '../../models/Store';
import { MetaTable } from '../../utils/globals';
import { NcUpgraderCtx } from '../NcUpgrader';
/** Upgrader for upgrading roles */
export default async function ({ ncMeta }: NcUpgraderCtx) {
const users = await ncMeta.metaList2(null, null, MetaTable.USERS);
const users = await ncMeta.metaList2(null, null, MetaTable.USER);
for (const user of users) {
user.roles = user.roles
@ -24,7 +24,7 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
await ncMeta.metaUpdate(
null,
null,
MetaTable.USERS,
MetaTable.USER,
{ roles: user.roles },
user.id
);
Loading…
Cancel
Save