Deprecate workspace datasoure (#16507)

This commit is contained in:
Weiko
2025-12-11 18:27:49 +01:00
committed by GitHub
parent 3dd2684254
commit 083a038f8a
39 changed files with 200 additions and 1929 deletions
@@ -140,7 +140,6 @@ describe('UpgradeCommandRunner', () => {
let upgradeCommandRunner: BasicUpgradeCommandRunner;
let workspaceRepository: Repository<WorkspaceEntity>;
let runCoreMigrationsSpy: jest.SpyInstance;
let globalWorkspaceOrmManagerSpy: GlobalWorkspaceOrmManager;
type BuildModuleAndSetupSpiesArgs = {
numberOfWorkspace?: number;
@@ -184,9 +183,6 @@ describe('UpgradeCommandRunner', () => {
workspaceRepository = module.get<Repository<WorkspaceEntity>>(
getRepositoryToken(WorkspaceEntity),
);
globalWorkspaceOrmManagerSpy = module.get<GlobalWorkspaceOrmManager>(
GlobalWorkspaceOrmManager,
);
};
it('should ignore and list as succesfull upgrade on workspace with higher version', async () => {
@@ -214,10 +210,9 @@ describe('UpgradeCommandRunner', () => {
expect(successReport.length).toBe(1);
expect(failReport.length).toBe(0);
[
globalWorkspaceOrmManagerSpy.destroyDataSourceForWorkspace,
upgradeCommandRunner.runOnWorkspace,
].forEach((fn) => expect(fn).toHaveBeenCalledTimes(1));
[upgradeCommandRunner.runOnWorkspace].forEach((fn) =>
expect(fn).toHaveBeenCalledTimes(1),
);
[workspaceRepository.update].forEach((fn) =>
expect(fn).not.toHaveBeenCalled(),
@@ -239,10 +234,9 @@ describe('UpgradeCommandRunner', () => {
// @ts-expect-error legacy noImplicitAny
await upgradeCommandRunner.run(passedParams, options);
[
upgradeCommandRunner.runOnWorkspace,
globalWorkspaceOrmManagerSpy.destroyDataSourceForWorkspace,
].forEach((fn) => expect(fn).toHaveBeenCalledTimes(numberOfWorkspace));
[upgradeCommandRunner.runOnWorkspace].forEach((fn) =>
expect(fn).toHaveBeenCalledTimes(numberOfWorkspace),
);
expect(workspaceRepository.update).toHaveBeenNthCalledWith(
numberOfWorkspace,
{ id: expect.any(String) },
@@ -4,11 +4,10 @@ import { isDefined } from 'twenty-shared/utils';
import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
import { In, MoreThanOrEqual, type Repository } from 'typeorm';
import { type WorkspaceDataSourceInterface } from 'src/engine/twenty-orm/interfaces/workspace-datasource.interface';
import { MigrationCommandRunner } from 'src/database/commands/command-runners/migration.command-runner';
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
import { GlobalWorkspaceDataSource } from 'src/engine/twenty-orm/global-workspace-datasource/global-workspace-datasource';
import { type GlobalWorkspaceOrmManager } from 'src/engine/twenty-orm/global-workspace-datasource/global-workspace-orm.manager';
import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';
@@ -23,7 +22,7 @@ export type WorkspacesMigrationCommandOptions = {
export type RunOnWorkspaceArgs = {
options: WorkspacesMigrationCommandOptions;
workspaceId: string;
dataSource?: WorkspaceDataSourceInterface;
dataSource?: GlobalWorkspaceDataSource;
index: number;
total: number;
};
@@ -151,9 +150,7 @@ export abstract class WorkspacesMigrationCommandRunner<
);
const dataSource = isDefined(workspaceHasDataSource)
? await this.globalWorkspaceOrmManager.getDataSourceForWorkspace(
workspaceId,
)
? await this.globalWorkspaceOrmManager.getGlobalWorkspaceDataSource()
: undefined;
await this.runOnWorkspace({
@@ -178,14 +175,6 @@ export abstract class WorkspacesMigrationCommandRunner<
chalk.red(`Error in workspace ${workspaceId}: ${error.message}`),
);
}
try {
await this.globalWorkspaceOrmManager.destroyDataSourceForWorkspace(
workspaceId,
);
} catch (error) {
this.logger.error(error);
}
}
this.migrationReport.fail.forEach(({ error, workspaceId }) =>
@@ -6,14 +6,13 @@ import { FieldMetadataType } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { Repository } from 'typeorm';
import { type WorkspaceDataSourceInterface } from 'src/engine/twenty-orm/interfaces/workspace-datasource.interface';
import { ActiveOrSuspendedWorkspacesMigrationCommandRunner } from 'src/database/commands/command-runners/active-or-suspended-workspaces-migration.command-runner';
import { RunOnWorkspaceArgs } from 'src/database/commands/command-runners/workspaces-migration.command-runner';
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { GlobalWorkspaceDataSource } from 'src/engine/twenty-orm/global-workspace-datasource/global-workspace-datasource';
import { GlobalWorkspaceOrmManager } from 'src/engine/twenty-orm/global-workspace-datasource/global-workspace-orm.manager';
import { computeObjectTargetTable } from 'src/engine/utils/compute-object-target-table.util';
import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';
@@ -114,7 +113,7 @@ export class CleanEmptyStringNullInTextFieldsCommand extends ActiveOrSuspendedWo
objectMetadataItem: ObjectMetadataEntity,
tableName: string,
schemaName: string,
dataSource: WorkspaceDataSourceInterface,
dataSource: GlobalWorkspaceDataSource,
isDryRun: boolean,
): Promise<void> {
const textFields = objectMetadataItem.fields.filter(
@@ -155,7 +154,7 @@ export class CleanEmptyStringNullInTextFieldsCommand extends ActiveOrSuspendedWo
objectMetadataItem: ObjectMetadataEntity,
tableName: string,
schemaName: string,
dataSource: WorkspaceDataSourceInterface,
dataSource: GlobalWorkspaceDataSource,
isDryRun: boolean,
): Promise<void> {
const nameField = objectMetadataItem.fields.find(