Browse Source

Merge pull request #1759 from nocodb/fix/1753-pg-out-of-sync-issue

fix: Postgres meta out of sync
pull/1845/head
աɨռɢӄաօռɢ 3 years ago committed by GitHub
parent
commit
0a1e05b044
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      packages/nocodb/src/lib/noco/meta/api/columnApis.ts
  2. 22
      packages/nocodb/src/lib/noco/meta/api/tableApis.ts

12
packages/nocodb/src/lib/noco/meta/api/columnApis.ts

@ -30,6 +30,7 @@ import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { NcError } from '../helpers/catchError'; import { NcError } from '../helpers/catchError';
import getColumnPropsFromUIDT from '../helpers/getColumnPropsFromUIDT'; import getColumnPropsFromUIDT from '../helpers/getColumnPropsFromUIDT';
import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue'; import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import NcConnectionMgrv2 from '../../common/NcConnectionMgrv2';
const randomID = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 10); const randomID = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 10);
@ -481,10 +482,21 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
] ]
}; };
const sqlClient = NcConnectionMgrv2.getSqlClient(base);
const sqlMgr = await ProjectMgrv2.getSqlMgr({ id: base.project_id }); const sqlMgr = await ProjectMgrv2.getSqlMgr({ id: base.project_id });
await sqlMgr.sqlOpPlus(base, 'tableUpdate', tableUpdateBody); await sqlMgr.sqlOpPlus(base, 'tableUpdate', tableUpdateBody);
const columns: Array<Omit<Column, 'column_name' | 'title'> & {
cn: string;
system?: boolean;
}> = (await sqlClient.columnList({ tn: table.table_name }))?.data?.list;
const insertedColumnMeta =
columns.find(c => c.cn === colBody.column_name) || {};
await Column.insert({ await Column.insert({
...colBody, ...colBody,
...insertedColumnMeta,
fk_model_id: table.id fk_model_id: table.id
}); });
} }

22
packages/nocodb/src/lib/noco/meta/api/tableApis.ts

@ -19,7 +19,10 @@ import View from '../../../noco-models/View';
import getColumnPropsFromUIDT from '../helpers/getColumnPropsFromUIDT'; import getColumnPropsFromUIDT from '../helpers/getColumnPropsFromUIDT';
import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue'; import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import { NcError } from '../helpers/catchError'; import { NcError } from '../helpers/catchError';
import getTableNameAlias from '../helpers/getTableName'; import getTableNameAlias, { getColumnNameAlias } from '../helpers/getTableName';
import Column from '../../../noco-models/Column';
import NcConnectionMgrv2 from '../../common/NcConnectionMgrv2';
import getColumnUiType from '../helpers/getColumnUiType';
export async function tableGet(req: Request, res: Response<TableType>) { export async function tableGet(req: Request, res: Response<TableType>) {
const table = await Model.getWithInfo({ const table = await Model.getWithInfo({
id: req.params.tableId id: req.params.tableId
@ -124,6 +127,8 @@ export async function tableCreate(req: Request<any, any, TableReqType>, res) {
} }
const sqlMgr = await ProjectMgrv2.getSqlMgr(project); const sqlMgr = await ProjectMgrv2.getSqlMgr(project);
const sqlClient = NcConnectionMgrv2.getSqlClient(base);
req.body.columns = req.body.columns?.map(c => ({ req.body.columns = req.body.columns?.map(c => ({
...getColumnPropsFromUIDT(c as any, base), ...getColumnPropsFromUIDT(c as any, base),
cn: c.column_name cn: c.column_name
@ -133,6 +138,11 @@ export async function tableCreate(req: Request<any, any, TableReqType>, res) {
tn: req.body.table_name tn: req.body.table_name
}); });
const columns: Array<Omit<Column, 'column_name' | 'title'> & {
cn: string;
system?: boolean;
}> = (await sqlClient.columnList({ tn: req.body.table_name }))?.data?.list;
const tables = await Model.list({ const tables = await Model.list({
project_id: project.id, project_id: project.id,
base_id: base.id base_id: base.id
@ -154,7 +164,15 @@ export async function tableCreate(req: Request<any, any, TableReqType>, res) {
res.json( res.json(
await Model.insert(project.id, base.id, { await Model.insert(project.id, base.id, {
...req.body, ...req.body,
// todo: sanitise columns: columns.map((c, i) => ({
uidt: c.uidt || getColumnUiType(base, c),
...c,
title:
req.body?.columns?.find(c1 => c.cn === c1.column_name)?.title ||
getColumnNameAlias(c.cn, base),
column_name: c.cn,
order: i + 1
})),
order: +(tables?.pop()?.order ?? 0) + 1 order: +(tables?.pop()?.order ?? 0) + 1
}) })
); );

Loading…
Cancel
Save