-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Trompette
committed
Mar 25, 2024
1 parent
d344cf5
commit ea27f6c
Showing
10 changed files
with
81 additions
and
62 deletions.
There are no files selected for viewing
15 changes: 0 additions & 15 deletions
15
...nty-server/src/database/typeorm/metadata/migrations/1711124466598-addRemoteServerTable.ts
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
...nty-server/src/database/typeorm/metadata/migrations/1711374137222-addRemoteServerTable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddRemoteServerTable1711374137222 implements MigrationInterface { | ||
name = 'AddRemoteServerTable1711374137222'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "metadata"."remoteServer" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "foreignDataWrapperId" uuid NOT NULL DEFAULT uuid_generate_v4(), "foreignDataWrapperType" character varying, "foreignDataWrapperOptions" jsonb, "userMappingOptions" jsonb, "workspaceId" uuid NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_8e5d208498fa2c9710bb934023a" PRIMARY KEY ("id"))`, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP TABLE "metadata"."remoteServer"`); | ||
} | ||
} |
48 changes: 28 additions & 20 deletions
48
...ngine/api/graphql/workspace-query-builder/factories/foreign-data-wrapper-query.factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,48 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { | ||
FdwOptions, | ||
ForeignDataWrapperOptions, | ||
RemoteServerType, | ||
UserMappingOptions, | ||
} from 'src/engine/metadata-modules/remote-server/remote-server.entity'; | ||
|
||
@Injectable() | ||
export class ForeignDataWrapperQueryFactory { | ||
createFDW( | ||
fdwId: string, | ||
fdwType: RemoteServerType, | ||
fdwOptions: FdwOptions<RemoteServerType>, | ||
createForeignDataWrapper( | ||
foreignDataWrapperId: string, | ||
foreignDataWrapperType: RemoteServerType, | ||
foreignDataWrapperOptions: ForeignDataWrapperOptions<RemoteServerType>, | ||
) { | ||
let fdwName = ''; | ||
let options = ''; | ||
const [name, options] = this.buildNameAndOptionsFromType( | ||
foreignDataWrapperType, | ||
foreignDataWrapperOptions, | ||
); | ||
|
||
switch (fdwType) { | ||
case RemoteServerType.POSTGRES_FDW: | ||
fdwName = 'postgres_fdw'; | ||
options = this.buildPostgresFDWQueryOptions(fdwOptions); | ||
break; | ||
default: | ||
throw new Error('FDW type not supported'); | ||
} | ||
return `CREATE SERVER "${foreignDataWrapperId}" FOREIGN DATA WRAPPER ${name} OPTIONS (${options})`; | ||
} | ||
|
||
return `CREATE SERVER IF NOT EXISTS "${fdwId}" FOREIGN DATA WRAPPER ${fdwName} OPTIONS (${options})`; | ||
createUserMapping( | ||
foreignDataWrapperId: string, | ||
userMappingOptions: UserMappingOptions, | ||
) { | ||
return `CREATE USER MAPPING IF NOT EXISTS FOR ${userMappingOptions.username} SERVER "${foreignDataWrapperId}" OPTIONS (user '${userMappingOptions.username}', password '${userMappingOptions.password}')`; | ||
} | ||
|
||
createUserMapping(fdwId: string, userMappingOptions: UserMappingOptions) { | ||
return `CREATE USER MAPPING IF NOT EXISTS FOR ${userMappingOptions.username} SERVER "${fdwId}" OPTIONS (user '${userMappingOptions.username}', password '${userMappingOptions.password}')`; | ||
private buildNameAndOptionsFromType( | ||
type: RemoteServerType, | ||
options: ForeignDataWrapperOptions<RemoteServerType>, | ||
) { | ||
switch (type) { | ||
case RemoteServerType.POSTGRES_FDW: | ||
return ['postgres_fdw', this.buildPostgresFDWQueryOptions(options)]; | ||
default: | ||
throw new Error('Foreign data wrapper type not supported'); | ||
} | ||
} | ||
|
||
private buildPostgresFDWQueryOptions( | ||
fdwOptions: FdwOptions<RemoteServerType>, | ||
foreignDataWrapperOptions: ForeignDataWrapperOptions<RemoteServerType>, | ||
) { | ||
return `dbname '${fdwOptions.dbname}', host '${fdwOptions.host}', port '${fdwOptions.port}'`; | ||
return `dbname '${foreignDataWrapperOptions.dbname}', host '${foreignDataWrapperOptions.host}', port '${foreignDataWrapperOptions.port}'`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters