Files
twenty/packages/twenty-server/src/database/commands/compute-twenty-standard-workspace-migration.command.ts
T
Paul Rastoin 942d2fef83 Remove sync-metadata and IS_WORKSPACE_CREATION_V2_ENABLED feature flag (#16997)
# Introduction
Followup of
https://github.com/twentyhq/twenty/pull/17001#pullrequestreview-3638508738
close https://github.com/twentyhq/core-team-issues/issues/1910

We've completely decom the `sync-metadata` in production. We're now then
removing its implementation in favor of the v2.

## TODO:
- [x] Remove sync-metadata implem and commands
- [x] Remove workspace decorators 
- [x] Type each deprecated field to deprecated on their workspaceEntity
- [x] Remove the `workspace-sync-metadata` folder entirely
- [x] remove workspace migration
- [x] workspace migration removal migration
- [x] remove the `v2` references from workspace manager file names
- [x] remove the `v2` references from workspace manager modules
- [ ] Double check impact on translation file path updates


## Note
- Removed the gate logic
- Remains some service v2 naming, serverless needs to be migrated on v2
fully
- Removed workspaceMigration service app health consumption, making it
always returning up ( no more down ) cc @FelixMalfait ( quite obsolete
health check now, will require complete refactor once we introduce inter
app dependency etc )
2026-01-08 15:45:12 +00:00

114 lines
4.3 KiB
TypeScript

import { Logger } from '@nestjs/common';
import { writeFileSync } from 'fs';
import { Command, CommandRunner } from 'nest-commander';
import { WorkspaceMigrationV2ExceptionCode } from 'twenty-shared/metadata';
import { createEmptyFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/constant/create-empty-flat-entity-maps.constant';
import { AdditionalCacheDataMaps } from 'src/engine/workspace-cache/types/workspace-cache-key.type';
import { computeTwentyStandardApplicationAllFlatEntityMaps } from 'src/engine/workspace-manager/twenty-standard-application/utils/twenty-standard-application-all-flat-entity-maps.constant';
import { WorkspaceMigrationV2Exception } from 'src/engine/workspace-manager/workspace-migration.exception';
import { WorkspaceMigrationBuildOrchestratorService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-build-orchestrator.service';
@Command({
name: 'workspace:compute-twenty-standard-migration',
description: 'Compute Twenty standard workspace migration.',
})
export class ComputeTwentyStandardWorkspaceMigrationCommand extends CommandRunner {
private readonly logger = new Logger(
ComputeTwentyStandardWorkspaceMigrationCommand.name,
);
constructor(
private readonly workspaceMigrationBuildOrchestratorService: WorkspaceMigrationBuildOrchestratorService,
) {
super();
}
async run(): Promise<void> {
this.logger.log('Starting compute Twenty standard workspace migration...');
// TODO: Implement migration logic here
const workspaceId = '20202020-ef6f-4118-953c-2b027324b54a';
const twentyStandardApplicationId = '20202020-5adb-4091-81b7-d5be86a8bdd2';
const twentyStandardAllFlatEntityMaps =
computeTwentyStandardApplicationAllFlatEntityMaps({
now: new Date().toISOString(),
workspaceId,
twentyStandardApplicationId,
});
writeFileSync(
`${Date.now()}-all-flat-entity-maps.json`,
JSON.stringify(twentyStandardAllFlatEntityMaps, null, 2),
);
const validateAndBuildResult =
await this.workspaceMigrationBuildOrchestratorService
.buildWorkspaceMigration({
buildOptions: {
isSystemBuild: true,
},
fromToAllFlatEntityMaps: {
flatObjectMetadataMaps: {
from: createEmptyFlatEntityMaps(),
to: twentyStandardAllFlatEntityMaps.flatObjectMetadataMaps,
},
flatFieldMetadataMaps: {
from: createEmptyFlatEntityMaps(),
to: twentyStandardAllFlatEntityMaps.flatFieldMetadataMaps,
},
flatIndexMaps: {
from: createEmptyFlatEntityMaps(),
to: twentyStandardAllFlatEntityMaps.flatIndexMaps,
},
flatViewFieldMaps: {
from: createEmptyFlatEntityMaps(),
to: twentyStandardAllFlatEntityMaps.flatViewFieldMaps,
},
flatViewFilterMaps: {
from: createEmptyFlatEntityMaps(),
to: twentyStandardAllFlatEntityMaps.flatViewFilterMaps,
},
flatViewGroupMaps: {
from: createEmptyFlatEntityMaps(),
to: twentyStandardAllFlatEntityMaps.flatViewGroupMaps,
},
flatViewMaps: {
from: createEmptyFlatEntityMaps(),
to: twentyStandardAllFlatEntityMaps.flatViewMaps,
},
flatAgentMaps: {
from: createEmptyFlatEntityMaps(),
to: twentyStandardAllFlatEntityMaps.flatAgentMaps,
},
flatRoleMaps: {
from: createEmptyFlatEntityMaps(),
to: twentyStandardAllFlatEntityMaps.flatRoleMaps,
},
},
additionalCacheDataMaps: {
featureFlagsMap: {} as AdditionalCacheDataMaps['featureFlagsMap'],
},
workspaceId,
})
.catch((error) => {
this.logger.error(error);
throw new WorkspaceMigrationV2Exception(
WorkspaceMigrationV2ExceptionCode.BUILDER_INTERNAL_SERVER_ERROR,
error.message,
);
});
writeFileSync(
`${Date.now()}validate-and-build-result.json`,
JSON.stringify(validateAndBuildResult, null, 2),
);
this.logger.log(
'Compute Twenty standard workspace migration completed successfully.',
);
}
}