Skip to content

Commit

Permalink
Rename unsync functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Trompette committed Apr 17, 2024
1 parent 08e8d89 commit 2971e62
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ObjectType } from '@nestjs/graphql';

import {
Column,
CreateDateColumn,
Expand Down Expand Up @@ -34,7 +32,6 @@ export type UserMappingOptions = {
};

@Entity('remoteServer')
@ObjectType('RemoteServer')
export class RemoteServerEntity<T extends RemoteServerType> {
@PrimaryGeneratedColumn('uuid')
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ export class RemoteServerService<T extends RemoteServerType> {
throw new NotFoundException('Remote server does not exist');
}

await this.remoteTableService.unsyncByServerInput(
workspaceId,
remoteServer,
);
await this.remoteTableService.unsyncAll(workspaceId, remoteServer);

return this.metadataDataSource.transaction(
async (entityManager: EntityManager) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ObjectType } from '@nestjs/graphql';

import {
Entity,
PrimaryGeneratedColumn,
Expand All @@ -17,7 +15,6 @@ import {
} from 'src/engine/metadata-modules/remote-server/remote-server.entity';

@Entity('remoteTable')
@ObjectType('RemoteTable')
export class RemoteTableEntity {
@PrimaryGeneratedColumn('uuid')
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ export class RemoteTableService {
}

public async syncRemoteTable(input: RemoteTableInput, workspaceId: string) {
if (!input.schema) {
throw new BadRequestException(
'Schema is required for syncing remote table',
);
}

const remoteServer = await this.remoteServerRepository.findOne({
where: {
id: input.remoteServerId,
Expand All @@ -106,12 +112,6 @@ export class RemoteTableService {
throw new NotFoundException('Remote server does not exist');
}

if (!input.schema) {
throw new BadRequestException(
'Schema is required for syncing remote table',
);
}

const currentRemoteTableWithSameDistantName =
await this.remoteTableRepository.findOne({
where: {
Expand All @@ -132,7 +132,7 @@ export class RemoteTableService {

const localTableName = getRemoteTableLocalName(input.name);

this.validateTableNameDoesNotExists(
await this.validateTableNameDoesNotExists(
localTableName,
workspaceId,
dataSourceMetatada.schema,
Expand Down Expand Up @@ -202,7 +202,7 @@ export class RemoteTableService {
throw new NotFoundException('Remote table does not exist');
}

await this.unsyncByTableInput(workspaceId, remoteTable, remoteServer);
await this.unsyncOne(workspaceId, remoteTable, remoteServer);

return {
name: input.name,
Expand All @@ -211,7 +211,7 @@ export class RemoteTableService {
};
}

public async unsyncByServerInput(
public async unsyncAll(
workspaceId: string,
remoteServer: RemoteServerEntity<RemoteServerType>,
) {
Expand All @@ -223,11 +223,11 @@ export class RemoteTableService {
});

for (const remoteTable of remoteTables) {
await this.unsyncByTableInput(workspaceId, remoteTable, remoteServer);
await this.unsyncOne(workspaceId, remoteTable, remoteServer);
}
}

private async unsyncByTableInput(
private async unsyncOne(
workspaceId: string,
remoteTable: RemoteTableEntity,
remoteServer: RemoteServerEntity<RemoteServerType>,
Expand Down Expand Up @@ -360,7 +360,7 @@ export class RemoteTableService {
) {
if (!remoteTableInput.schema) {
throw new BadRequestException(
'Schema is required for syncing remote table',
'Schema is required for creating foreign table',
);
}

Expand Down

0 comments on commit 2971e62

Please sign in to comment.