Browse Source

fix: populate random foreign key constraint name, m2m relation creation bug fix

re #913

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/979/head
Pranav C 3 years ago
parent
commit
a5cb850e75
  1. 6
      packages/nc-gui/components/project/spreadsheet/components/pagination.vue
  2. 32
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
  3. 4
      packages/nocodb/src/lib/sqlMgr/SqlMgr.ts

6
packages/nc-gui/components/project/spreadsheet/components/pagination.vue

@ -1,8 +1,8 @@
<template>
<div class="d-flex align-center">
<v-spacer />
<span v-if="count && count > 1 && count !== Infinity" class="caption ml-2">Total {{ count }} rows found</span>
<span v-if="count !== null && count !== Infinity" class="caption ml-2">
{{ count }} record{{ count !== 1 ? 's' : '' }}
</span>
<v-spacer />
<v-pagination
v-if="count !== Infinity"

32
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -10,7 +10,7 @@ import express, { Handler, Router } from 'express';
import extract from 'extract-zip';
import isDocker from 'is-docker';
import multer from 'multer';
import { nanoid } from 'nanoid';
import { customAlphabet, nanoid } from 'nanoid';
import { SqlClientFactory, Tele } from 'nc-help';
import slash from 'slash';
import { v4 as uuidv4 } from 'uuid';
@ -40,7 +40,7 @@ import NcTemplateParser from '../../templateParser/NcTemplateParser';
import UITypes from '../../sqlUi/UITypes';
import { defaultConnectionConfig } from '../../utils/NcConfigFactory';
import xcMetaDiff from './handlers/xcMetaDiff';
const randomID = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 10);
const XC_PLUGIN_DET = 'XC_PLUGIN_DET';
const NOCO_RELEASE = 'NOCO_RELEASE';
@ -3020,10 +3020,13 @@ export default class NcMetaMgr {
const associateTableCols = [];
const parentCn = 'table1_id';
const childCn = 'table2_id';
associateTableCols.push(
{
cn: `${childMeta.tn}_c_id`,
_cn: `${childMeta._tn}CId`,
cn: childCn,
_cn: childCn,
rqd: true,
pk: true,
ai: false,
@ -3035,8 +3038,8 @@ export default class NcMetaMgr {
altered: 1
},
{
cn: `${parentMeta.tn}_p_id`,
_cn: `${parentMeta._tn}PId`,
cn: parentCn,
_cn: parentCn,
rqd: true,
pk: true,
ai: false,
@ -3050,9 +3053,8 @@ export default class NcMetaMgr {
);
// todo: associative table naming
const aTn = `${this.projectConfigs[projectId]?.prefix ?? ''}_nc_m2m_${
parentMeta.tn
}_${childMeta.tn}`;
const aTn = `${this.projectConfigs[projectId]?.prefix ??
''}_nc_m2m_${randomID()}`;
const aTnAlias = `m2m${parentMeta._tn}_${childMeta._tn}`;
const out = await this.projectMgr
@ -3088,25 +3090,17 @@ export default class NcMetaMgr {
const rel1Args = {
...args.args,
childTable: aTn,
childColumn: `${parentMeta.tn}_p_id`,
childColumn: parentCn,
parentTable: parentMeta.tn,
parentColumn: parentPK.cn,
foreignKeyName: `${parentMeta.tn.slice(0, 3)}_${childMeta.tn.slice(
0,
3
)}_${nanoid(6)}_p_fk`,
type: 'real'
};
const rel2Args = {
...args.args,
childTable: aTn,
childColumn: `${childMeta.tn}_c_id`,
childColumn: childCn,
parentTable: childMeta.tn,
parentColumn: childPK.cn,
foreignKeyName: `${parentMeta.tn.slice(0, 3)}_${childMeta.tn.slice(
0,
3
)}_${nanoid(6)}_c_fk`,
type: 'real'
};
if (args.args.type === 'real') {

4
packages/nocodb/src/lib/sqlMgr/SqlMgr.ts

@ -14,6 +14,8 @@ const log = new Debug('SqlMgr');
import KnexMigrator from '../migrator/SqlMigrator/lib/KnexMigrator';
// import {XKnex} from "../dataMapper";
import NcConnectionMgr from '../noco/common/NcConnectionMgr';
import { customAlphabet } from 'nanoid';
const randomID = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 20);
const ToolOps = {
DB_TABLE_LIST: 'tableList',
@ -1236,6 +1238,8 @@ export default class SqlMgr {
break;
case ToolOps.DB_TABLE_RELATION_CREATE:
console.log('Within DB_TABLE_RELATION_CREATE handler', args);
args.args.foreignKeyName =
args.args.foreignKeyName || `fk${randomID()}`;
result = await op(args, 'relationCreate', args.args);
break;
case ToolOps.DB_TABLE_INDEX_CREATE:

Loading…
Cancel
Save