Use migrations for remote tables (#4877)

Foreign tables should be created using migrations, as we do for standard
tables.
Since those are not really generated from the object metadata but from
the remote table, those migrations won't live in the object metadata
service.

This PR:
- creates new types of migration : create_foreign_table and
drop_foreign_table
- triggers those migrations rather than raw queries directly
- moves the logic to fetch current foreign tables into the remote table
service since this is not directly linked to postgres data wrapper
- adds logic to unsync all tables before deleting

---------

Co-authored-by: Thomas Trompette <thomast@twenty.com>
This commit is contained in:
Thomas Trompette
2024-04-08 18:21:29 +02:00
committed by GitHub
parent d4a9a26069
commit 651af1c0e1
10 changed files with 241 additions and 112 deletions

View File

@ -62,6 +62,13 @@ export type WorkspaceMigrationCreateComment = {
comment: string;
};
export type WorkspaceMigrationForeignTable = {
columns: WorkspaceMigrationColumnDefinition[];
referencedTableName: string;
referencedTableSchema: string;
foreignDataWrapperId: string;
};
export type WorkspaceMigrationColumnAction = {
action: WorkspaceMigrationColumnActionType;
} & (
@ -75,8 +82,14 @@ export type WorkspaceMigrationColumnAction = {
export type WorkspaceMigrationTableAction = {
name: string;
action: 'create' | 'alter' | 'drop';
action:
| 'create'
| 'alter'
| 'drop'
| 'create_foreign_table'
| 'drop_foreign_table';
columns?: WorkspaceMigrationColumnAction[];
foreignTable?: WorkspaceMigrationForeignTable;
};
@Entity('workspaceMigration')