Browse Source

fix: fetch column meta props from db on table create/update

closes #1049

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/1050/head
Pranav C 3 years ago
parent
commit
1d0c45d80e
  1. 10
      packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
  2. 15
      packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts
  3. 9
      packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts

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

@ -726,6 +726,9 @@ export default abstract class BaseApiBuilder<T extends Noco>
this.baseLog(`onTableUpdate : Getting old model meta for '%s'`, tn); this.baseLog(`onTableUpdate : Getting old model meta for '%s'`, tn);
XcCache.del([this.projectId, this.dbAlias, 'table', tn].join('::')); XcCache.del([this.projectId, this.dbAlias, 'table', tn].join('::'));
// get columns list from db
const columnsFromDb = await this.getColumnList(tn);
const relationTableMetas: Set<any> = new Set(); const relationTableMetas: Set<any> = new Set();
const oldModelRow = await this.xcMeta.metaGet( const oldModelRow = await this.xcMeta.metaGet(
@ -752,8 +755,11 @@ export default abstract class BaseApiBuilder<T extends Noco>
const columns = const columns =
changeObj.columns changeObj.columns
.filter(c => c.altered !== 4) .filter(c => c.altered !== 4)
.map(({ altered: _al, ...rest }) => rest) || .map(({ altered: _al, ...rest }) => ({
(await this.getColumnList(tn)); ...rest,
// find and overwrite column property from db
...(columnsFromDb?.find(c => c.cn === rest.cn) || {})
})) || (await this.getColumnList(tn));
/* Get all relations */ /* Get all relations */
const relations = await this.relationsSyncAndGet(); const relations = await this.relationsSyncAndGet();

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

@ -190,9 +190,18 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
await super.onTableCreate(tn, args); await super.onTableCreate(tn, args);
const columns = { // get columns list from db
[tn]: args?.columns?.map(({ altered: _al, ...rest }) => rest) const columnsFromDb = await this.getColumnList(tn);
};
const columns = args.columns
? {
[tn]: args.columns?.map(({ altered: _al, ...rest }) => ({
...rest,
// find and overwrite column property from db
...columnsFromDb?.find(c => c.cn === rest.cn)
}))
}
: {};
await this.xcTablesPopulate({ await this.xcTablesPopulate({
tableNames: [{ tn, _tn: args._tn }], tableNames: [{ tn, _tn: args._tn }],

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

@ -876,9 +876,16 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
): Promise<void> { ): Promise<void> {
await super.onTableCreate(tn, args); await super.onTableCreate(tn, args);
// get columns list from db
const columnsFromDb = await this.getColumnList(tn);
const columns = args.columns const columns = args.columns
? { ? {
[tn]: args.columns?.map(({ altered: _al, ...rest }) => rest) [tn]: args.columns?.map(({ altered: _al, ...rest }) => ({
...rest,
// find and overwrite column property from db
...(columnsFromDb?.find(c => c.cn === rest.cn) || {})
}))
} }
: {}; : {};

Loading…
Cancel
Save