Import full distant schema and store in remote server (#5211)
We should not depend on the foreign data wrapper type to manage distant table. The remote server should be enough to handle the table creation. Here is the new flow to fetch available tables: - check if the remote server have available tables already stored - if not, import full schema in a temporary schema - copy the tables into the available tables field - delete the schema Left todo: - update remote server input for postgres so we receive the schema --------- Co-authored-by: Thomas Trompette <thomast@twenty.com>
This commit is contained in:
@ -0,0 +1,40 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import {
|
||||
FeatureFlagEntity,
|
||||
FeatureFlagKeys,
|
||||
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
||||
import { RemoteServerType } from 'src/engine/metadata-modules/remote-server/remote-server.entity';
|
||||
|
||||
export const validateRemoteServerType = async (
|
||||
remoteServerType: RemoteServerType,
|
||||
featureFlagRepository: Repository<FeatureFlagEntity>,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
const featureFlagKey = getFeatureFlagKey(remoteServerType);
|
||||
|
||||
const featureFlag = await featureFlagRepository.findOneBy({
|
||||
workspaceId,
|
||||
key: featureFlagKey,
|
||||
value: true,
|
||||
});
|
||||
|
||||
const featureFlagEnabled = featureFlag && featureFlag.value;
|
||||
|
||||
if (!featureFlagEnabled) {
|
||||
throw new BadRequestException(`Type ${remoteServerType} is not supported.`);
|
||||
}
|
||||
};
|
||||
|
||||
const getFeatureFlagKey = (remoteServerType: RemoteServerType) => {
|
||||
switch (remoteServerType) {
|
||||
case RemoteServerType.POSTGRES_FDW:
|
||||
return FeatureFlagKeys.IsPostgreSQLIntegrationEnabled;
|
||||
default:
|
||||
throw new BadRequestException(
|
||||
`Type ${remoteServerType} is not supported.`,
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user