Skip to content

Commit

Permalink
Move id column check before foreign table creation (twentyhq#5029)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
thomtrp and Thomas Trompette authored Apr 18, 2024
1 parent bc5cfd0 commit b08e954
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -163,6 +172,7 @@ export class RemoteTableService {
workspaceId,
localTableName,
remoteTableColumns,
remoteTableIdColumn,
dataSourceMetatada.id,
);

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit b08e954

Please sign in to comment.