mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-23 05:53:31 +03:00
Fix get available tables (#4873)
Endpoint is broken since we now use `Remote` as a suffix for remote table names. This PR: - creates a common function to calculate the name of the remote table - use it in the `findAvailableRemotePostgresTables` to know if a table has been synced or not Co-authored-by: Thomas Trompette <thomast@twenty.com>
This commit is contained in:
parent
3eef4a8938
commit
2890a7a44a
@ -13,6 +13,7 @@ import {
|
||||
} from 'src/engine/metadata-modules/remote-server/remote-table/remote-postgres-table/utils/remote-postgres-table.util';
|
||||
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { getRemoteTableName } from 'src/engine/metadata-modules/remote-server/remote-table/utils/get-remote-table-name.util';
|
||||
|
||||
@Injectable()
|
||||
export class RemotePostgresTableService {
|
||||
@ -42,7 +43,9 @@ export class RemotePostgresTableService {
|
||||
return remotePostgresTables.map((remoteTable) => ({
|
||||
name: remoteTable.table_name,
|
||||
schema: remoteTable.table_schema,
|
||||
status: currentForeignTableNames.includes(remoteTable.table_name)
|
||||
status: currentForeignTableNames.includes(
|
||||
getRemoteTableName(remoteTable.table_name),
|
||||
)
|
||||
? RemoteTableStatus.SYNCED
|
||||
: RemoteTableStatus.NOT_SYNCED,
|
||||
}));
|
||||
|
@ -25,6 +25,7 @@ import { RemotePostgresTableService } from 'src/engine/metadata-modules/remote-s
|
||||
import { WorkspaceCacheVersionService } from 'src/engine/metadata-modules/workspace-cache-version/workspace-cache-version.service';
|
||||
import { camelCase } from 'src/utils/camel-case';
|
||||
import { camelToTitleCase } from 'src/utils/camel-to-title-case';
|
||||
import { getRemoteTableName } from 'src/engine/metadata-modules/remote-server/remote-table/utils/get-remote-table-name.util';
|
||||
|
||||
export class RemoteTableService {
|
||||
constructor(
|
||||
@ -149,7 +150,7 @@ export class RemoteTableService {
|
||||
.map((column) => `"${column.column_name}" ${column.data_type}`)
|
||||
.join(', ');
|
||||
|
||||
const remoteTableName = `${camelCase(input.name)}Remote`;
|
||||
const remoteTableName = getRemoteTableName(input.name);
|
||||
const remoteTableLabel = camelToTitleCase(remoteTableName);
|
||||
|
||||
// We only support remote tables with an id column for now.
|
||||
@ -211,9 +212,11 @@ export class RemoteTableService {
|
||||
workspaceDataSource: DataSource,
|
||||
localSchema: string,
|
||||
) {
|
||||
const remoteTableName = getRemoteTableName(input.name);
|
||||
|
||||
const objectMetadata =
|
||||
await this.objectMetadataService.findOneWithinWorkspace(workspaceId, {
|
||||
where: { nameSingular: `${input.name}Remote` },
|
||||
where: { nameSingular: remoteTableName },
|
||||
});
|
||||
|
||||
if (objectMetadata) {
|
||||
|
@ -0,0 +1,4 @@
|
||||
import { camelCase } from 'src/utils/camel-case';
|
||||
|
||||
export const getRemoteTableName = (distantTableName: string) =>
|
||||
`${camelCase(distantTableName)}Remote`;
|
Loading…
Reference in New Issue
Block a user