Browse Source

feat: compare all boolean props

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/6030/head
Pranav C 2 years ago
parent
commit
8e3f6cb6ed
  1. 52
      packages/nocodb/src/services/meta-diffs.service.ts

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

@ -17,7 +17,7 @@ export enum MetaDiffType {
TABLE_REMOVE = 'TABLE_REMOVE', TABLE_REMOVE = 'TABLE_REMOVE',
TABLE_COLUMN_ADD = 'TABLE_COLUMN_ADD', TABLE_COLUMN_ADD = 'TABLE_COLUMN_ADD',
TABLE_COLUMN_TYPE_CHANGE = 'TABLE_COLUMN_TYPE_CHANGE', TABLE_COLUMN_TYPE_CHANGE = 'TABLE_COLUMN_TYPE_CHANGE',
TABLE_COLUMN_PK_CHANGED = 'TABLE_COLUMN_PK_CHANGED', TABLE_COLUMN_PROPS_CHANGED = 'TABLE_COLUMN_PROPS_CHANGED',
TABLE_COLUMN_REMOVE = 'TABLE_COLUMN_REMOVE', TABLE_COLUMN_REMOVE = 'TABLE_COLUMN_REMOVE',
VIEW_NEW = 'VIEW_NEW', VIEW_NEW = 'VIEW_NEW',
VIEW_REMOVE = 'VIEW_REMOVE', VIEW_REMOVE = 'VIEW_REMOVE',
@ -105,14 +105,13 @@ type MetaDiffChange = {
cstn?: string; cstn?: string;
} }
| { | {
type: MetaDiffType.TABLE_COLUMN_PK_CHANGED; type: MetaDiffType.TABLE_COLUMN_PROPS_CHANGED;
tn?: string; tn?: string;
model?: Model; model?: Model;
id?: string; id?: string;
cn: string; cn: string;
column: Column; column: Column;
colId?: string; colId?: string;
status: 'removed' | 'added';
} }
); );
@ -228,16 +227,18 @@ export class MetaDiffsService {
column: oldCol, column: oldCol,
}); });
} }
if (!!oldCol.pk !== !!column.pk) { if (
!!oldCol.pk !== !!column.pk ||
!!oldCol.rqd !== !!column.rqd ||
!!oldCol.un !== !!column.un ||
!!oldCol.ai !== !!column.ai
) {
tableProp.detectedChanges.push({ tableProp.detectedChanges.push({
type: MetaDiffType.TABLE_COLUMN_PK_CHANGED, type: MetaDiffType.TABLE_COLUMN_PROPS_CHANGED,
msg: column.pk msg: `Column properties changed (${column.cn})`,
? `Column ${column.cn} is new primary key`
: `Column ${column.cn} is no longer primary key`,
cn: oldCol.column_name, cn: oldCol.column_name,
id: oldMeta.id, id: oldMeta.id,
column: oldCol, column: oldCol,
status: column.pk ? 'added' : 'removed',
}); });
} }
} }
@ -711,11 +712,20 @@ export class MetaDiffsService {
await Column.update(change.column.id, column); await Column.update(change.column.id, column);
} }
break; break;
case MetaDiffType.TABLE_COLUMN_PK_CHANGED: case MetaDiffType.TABLE_COLUMN_PROPS_CHANGED:
{ {
const column = change.column; const columns = (
column.pk = change.status === 'added'; await sqlClient.columnList({ tn: table_name })
await Column.update(change.column.id, column); )?.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 } = colMeta;
await Column.update(change.column.id, {
pk,
ai,
rqd,
un,
});
} }
break; break;
case MetaDiffType.TABLE_COLUMN_REMOVE: case MetaDiffType.TABLE_COLUMN_REMOVE:
@ -914,6 +924,22 @@ export class MetaDiffsService {
await Column.update(change.column.id, column); await Column.update(change.column.id, column);
} }
break; 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 } = colMeta;
await Column.update(change.column.id, {
pk,
ai,
rqd,
un,
});
}
break;
case MetaDiffType.TABLE_COLUMN_REMOVE: case MetaDiffType.TABLE_COLUMN_REMOVE:
case MetaDiffType.VIEW_COLUMN_REMOVE: case MetaDiffType.VIEW_COLUMN_REMOVE:
await change.column.delete(); await change.column.delete();

Loading…
Cancel
Save