Move id column check before foreign table creation (#5029)

When distant table does not have an id column, syncing does not work.
Today the check is only made after creating the foreign table locally.
We should do it first, so we avoid having a foreign table created and
failing right after.

Co-authored-by: Thomas Trompette <thomast@twenty.com>
This commit is contained in:
Thomas Trompette 2024-04-18 11:34:21 +02:00 committed by GitHub
parent bc5cfd046c
commit b08e95494c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -151,6 +151,15 @@ export class RemoteTableService {
input.schema,
);
// We only support remote tables with an id column for now.
const remoteTableIdColumn = remoteTableColumns.find(
(column) => column.columnName === 'id',
);
if (!remoteTableIdColumn) {
throw new BadRequestException('Remote table must have an id column');
}
await this.createForeignTable(
workspaceId,
localTableName,
@ -163,6 +172,7 @@ export class RemoteTableService {
workspaceId,
localTableName,
remoteTableColumns,
remoteTableIdColumn,
dataSourceMetatada.id,
);
@ -406,17 +416,9 @@ export class RemoteTableService {
workspaceId: string,
localTableName: string,
remoteTableColumns: RemoteTableColumn[],
remoteTableIdColumn: RemoteTableColumn,
dataSourceMetadataId: string,
) {
// We only support remote tables with an id column for now.
const remoteTableIdColumn = remoteTableColumns.filter(
(column) => column.columnName === 'id',
)?.[0];
if (!remoteTableIdColumn) {
throw new BadRequestException('Remote table must have an id column');
}
const objectMetadata = await this.objectMetadataService.createOne({
nameSingular: localTableName,
namePlural: plural(localTableName),