Browse Source

Merge pull request #6030 from nocodb/feat/6018-pk-support-with-meta-sync

feat: Identify removed/added primary key in meta sync
pull/6036/head
Pranav C 1 year ago committed by GitHub
parent
commit
f9f6fd5755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      packages/nocodb/src/models/Column.ts
  2. 59
      packages/nocodb/src/services/meta-diffs.service.ts

24
packages/nocodb/src/models/Column.ts

@ -1075,6 +1075,30 @@ export default class Column<T = any> implements ColumnType {
// set cache
await NocoCache.set(key, o);
}
// get model column list from cache
const columnListFromCache = await NocoCache.getList(CacheScope.COLUMN, [
oldCol.fk_model_id,
]);
// update column list in cache if cache exists
if (!columnListFromCache.list?.length) {
const updatedColumnList = columnListFromCache.list.map((column: any) => {
if (column.id === colId) {
return {
...column,
...updateObj,
};
}
return column;
});
await NocoCache.setList(
CacheScope.COLUMN,
[oldCol.fk_model_id],
updatedColumnList,
);
}
// set meta
await ncMeta.metaUpdate(
null,

59
packages/nocodb/src/services/meta-diffs.service.ts

@ -17,6 +17,7 @@ export enum MetaDiffType {
TABLE_REMOVE = 'TABLE_REMOVE',
TABLE_COLUMN_ADD = 'TABLE_COLUMN_ADD',
TABLE_COLUMN_TYPE_CHANGE = 'TABLE_COLUMN_TYPE_CHANGE',
TABLE_COLUMN_PROPS_CHANGED = 'TABLE_COLUMN_PROPS_CHANGED',
TABLE_COLUMN_REMOVE = 'TABLE_COLUMN_REMOVE',
VIEW_NEW = 'VIEW_NEW',
VIEW_REMOVE = 'VIEW_REMOVE',
@ -103,6 +104,15 @@ type MetaDiffChange = {
relationType: RelationTypes;
cstn?: string;
}
| {
type: MetaDiffType.TABLE_COLUMN_PROPS_CHANGED;
tn?: string;
model?: Model;
id?: string;
cn: string;
column: Column;
colId?: string;
}
);
@Injectable()
@ -217,6 +227,21 @@ export class MetaDiffsService {
column: oldCol,
});
}
if (
!!oldCol.pk !== !!column.pk ||
!!oldCol.rqd !== !!column.rqd ||
!!oldCol.un !== !!column.un ||
!!oldCol.ai !== !!column.ai ||
!!oldCol.unique !== !!column.unique
) {
tableProp.detectedChanges.push({
type: MetaDiffType.TABLE_COLUMN_PROPS_CHANGED,
msg: `Column properties changed (${column.cn})`,
cn: oldCol.column_name,
id: oldMeta.id,
column: oldCol,
});
}
}
for (const column of oldMeta.columns) {
if (
@ -688,6 +713,23 @@ export class MetaDiffsService {
await Column.update(change.column.id, column);
}
break;
case MetaDiffType.TABLE_COLUMN_PROPS_CHANGED:
{
const columns = (
await sqlClient.columnList({ tn: table_name })
)?.data?.list?.map((c) => ({ ...c, column_name: c.cn }));
const colMeta = columns.find((c) => c.cn === change.cn);
if (!colMeta) break;
const { pk, ai, rqd, un, unique } = colMeta;
await Column.update(change.column.id, {
pk,
ai,
rqd,
un,
unique,
});
}
break;
case MetaDiffType.TABLE_COLUMN_REMOVE:
case MetaDiffType.VIEW_COLUMN_REMOVE:
await change.column.delete();
@ -884,6 +926,23 @@ export class MetaDiffsService {
await Column.update(change.column.id, column);
}
break;
case MetaDiffType.TABLE_COLUMN_PROPS_CHANGED:
{
const columns = (
await sqlClient.columnList({ tn: table_name })
)?.data?.list?.map((c) => ({ ...c, column_name: c.cn }));
const colMeta = columns.find((c) => c.cn === change.cn);
if (!colMeta) break;
const { pk, ai, rqd, un, unique } = colMeta;
await Column.update(change.column.id, {
pk,
ai,
rqd,
un,
unique,
});
}
break;
case MetaDiffType.TABLE_COLUMN_REMOVE:
case MetaDiffType.VIEW_COLUMN_REMOVE:
await change.column.delete();

Loading…
Cancel
Save