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 REDIS_URL=redis://localhost:6379
APP_SECRET=replace_me_with_a_random_string APP_SECRET=replace_me_with_a_random_string
SIGN_IN_PREFILLED=true SIGN_IN_PREFILLED=true
SYNC_METADATA_INDEX_ENABLED=false
FRONTEND_URL=http://localhost:3001 FRONTEND_URL=http://localhost:3001

View File

@ -28,15 +28,6 @@ export function WorkspaceFieldIndex(
...additionalDefaultColumnsForIndex, ...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({ metadataArgsStorage.addIndexes({
name: `IDX_${generateDeterministicIndexName([ name: `IDX_${generateDeterministicIndexName([
convertClassNameToObjectMetadataName(target.constructor.name), convertClassNameToObjectMetadataName(target.constructor.name),

View File

@ -18,15 +18,6 @@ export function WorkspaceIndex(
throw new Error('Class level WorkspaceIndex should be used with columns'); 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) => { return (target: any) => {
const gate = TypedReflect.getMetadata( const gate = TypedReflect.getMetadata(
'workspace:gate-metadata-args', 'workspace:gate-metadata-args',

View File

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

View File

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