Fix broken metadata sync due to index removal (#11706)

Changing strategy regarding disabling index creation with new relation
system
This commit is contained in:
Charles Bochet
2025-04-23 18:06:19 +02:00
committed by GitHub
parent 4257f30f12
commit 8076ff5b82
5 changed files with 27 additions and 45 deletions

View File

@ -4,7 +4,6 @@ PG_DATABASE_URL=postgres://postgres:postgres@localhost:5432/default
REDIS_URL=redis://localhost:6379
APP_SECRET=replace_me_with_a_random_string
SIGN_IN_PREFILLED=true
SYNC_METADATA_INDEX_ENABLED=false
FRONTEND_URL=http://localhost:3001

View File

@ -28,15 +28,6 @@ export function WorkspaceFieldIndex(
...additionalDefaultColumnsForIndex,
];
// TODO: Remove this when we are handling properly indexes for new relation metadata
if (
process.env.SYNC_METADATA_INDEX_ENABLED === 'false' ||
process.env.SYNC_METADATA_INDEX_ENABLED === '' ||
process.env.SYNC_METADATA_INDEX_ENABLED === undefined
) {
return;
}
metadataArgsStorage.addIndexes({
name: `IDX_${generateDeterministicIndexName([
convertClassNameToObjectMetadataName(target.constructor.name),

View File

@ -18,15 +18,6 @@ export function WorkspaceIndex(
throw new Error('Class level WorkspaceIndex should be used with columns');
}
// TODO: Remove this when we are handling properly indexes for new relation metadata
if (
process.env.SYNC_METADATA_INDEX_ENABLED === 'false' ||
process.env.SYNC_METADATA_INDEX_ENABLED === '' ||
process.env.SYNC_METADATA_INDEX_ENABLED === undefined
) {
return (_target: any) => {};
}
return (target: any) => {
const gate = TypedReflect.getMetadata(
'workspace:gate-metadata-args',

View File

@ -17,20 +17,17 @@ export function WorkspaceIsUnique(): PropertyDecorator {
const columns = [propertyKey.toString()];
// TODO: Remove this when we are handling properly indexes for new relation metadata
if (process.env.SYNC_METADATA_INDEX_ENABLED === 'true') {
metadataArgsStorage.addIndexes({
name: `IDX_UNIQUE_${generateDeterministicIndexName([
convertClassNameToObjectMetadataName(target.constructor.name),
...columns,
])}`,
columns,
target: target.constructor,
gate,
isUnique: true,
whereClause: null,
});
}
metadataArgsStorage.addIndexes({
name: `IDX_UNIQUE_${generateDeterministicIndexName([
convertClassNameToObjectMetadataName(target.constructor.name),
...columns,
])}`,
columns,
target: target.constructor,
gate,
isUnique: true,
whereClause: null,
});
return TypedReflect.defineMetadata(
'workspace:is-unique-metadata-args',

View File

@ -149,20 +149,24 @@ export class WorkspaceSyncMetadataService {
`Workspace relation migrations took ${workspaceRelationMigrationsEnd - workspaceRelationMigrationsStart}ms`,
);
let workspaceIndexMigrations: Partial<WorkspaceMigrationEntity>[] = [];
// 4 - Sync standard indexes on standard objects
const workspaceIndexMigrationsStart = performance.now();
const workspaceIndexMigrations =
await this.workspaceSyncIndexMetadataService.synchronize(
context,
manager,
storage,
if (!isNewRelationEnabled) {
const workspaceIndexMigrationsStart = performance.now();
workspaceIndexMigrations =
await this.workspaceSyncIndexMetadataService.synchronize(
context,
manager,
storage,
);
const workspaceIndexMigrationsEnd = performance.now();
this.logger.log(
`Workspace index migrations took ${workspaceIndexMigrationsEnd - workspaceIndexMigrationsStart}ms`,
);
const workspaceIndexMigrationsEnd = performance.now();
this.logger.log(
`Workspace index migrations took ${workspaceIndexMigrationsEnd - workspaceIndexMigrationsStart}ms`,
);
}
// 5 - Sync standard object metadata identifiers, does not need to return nor apply migrations
const workspaceObjectMetadataIdentifiersStart = performance.now();