Browse Source

feat: identify removed/added pk columns

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/6030/head
Pranav C 1 year ago
parent
commit
57e677242f
  1. 30
      packages/nocodb/src/services/meta-diffs.service.ts

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

@ -17,6 +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_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',
@ -103,6 +104,16 @@ type MetaDiffChange = {
relationType: RelationTypes; relationType: RelationTypes;
cstn?: string; cstn?: string;
} }
| {
type: MetaDiffType.TABLE_COLUMN_PK_CHANGED;
tn?: string;
model?: Model;
id?: string;
cn: string;
column: Column;
colId?: string;
status: 'removed' | 'added';
}
); );
@Injectable() @Injectable()
@ -217,6 +228,18 @@ export class MetaDiffsService {
column: oldCol, column: oldCol,
}); });
} }
if (!!oldCol.pk !== !!column.pk) {
tableProp.detectedChanges.push({
type: MetaDiffType.TABLE_COLUMN_PK_CHANGED,
msg: column.pk
? `Column ${column.cn} is new primary key`
: `Column ${column.cn} is no longer primary key`,
cn: oldCol.column_name,
id: oldMeta.id,
column: oldCol,
status: column.pk ? 'added' : 'removed',
});
}
} }
for (const column of oldMeta.columns) { for (const column of oldMeta.columns) {
if ( if (
@ -688,6 +711,13 @@ 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:
{
const column = change.column;
column.pk = change.status === 'added';
await Column.update(change.column.id, column);
}
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