Update foreign table to distant table schema (#5508)
Closes #5069 back-end part And: - do not display schemaPendingUpdates status on remote server lists as this call will become too costly if there are dozens of servers - (refacto) create foreignTableService After this is merged we will be able to delete remoteTable's availableTables column
This commit is contained in:
@ -155,6 +155,14 @@ export class WorkspaceMigrationRunnerService {
|
||||
`DROP FOREIGN TABLE ${schemaName}."${tableMigration.name}"`,
|
||||
);
|
||||
break;
|
||||
case WorkspaceMigrationTableActionType.ALTER_FOREIGN_TABLE:
|
||||
await this.alterForeignTable(
|
||||
queryRunner,
|
||||
schemaName,
|
||||
tableMigration.name,
|
||||
tableMigration.columns,
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Migration table action ${tableMigration.action} not supported`,
|
||||
@ -507,4 +515,29 @@ export class WorkspaceMigrationRunnerService {
|
||||
COMMENT ON FOREIGN TABLE "${schemaName}"."${name}" IS '@graphql({"primary_key_columns": ["id"], "totalCount": {"enabled": true}})';
|
||||
`);
|
||||
}
|
||||
|
||||
private async alterForeignTable(
|
||||
queryRunner: QueryRunner,
|
||||
schemaName: string,
|
||||
name: string,
|
||||
columns: WorkspaceMigrationColumnAction[] | undefined,
|
||||
) {
|
||||
const columnUpdatesQuery = columns
|
||||
?.map((column) => {
|
||||
switch (column.action) {
|
||||
case WorkspaceMigrationColumnActionType.DROP:
|
||||
return `DROP COLUMN "${column.columnName}"`;
|
||||
case WorkspaceMigrationColumnActionType.CREATE:
|
||||
return `ADD COLUMN "${column.columnName}" ${column.columnType}`;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join(', ');
|
||||
|
||||
await queryRunner.query(
|
||||
`ALTER FOREIGN TABLE ${schemaName}."${name}" ${columnUpdatesQuery};`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user