fixing index on relations (#12602)
## Why After the changes on relations, index on relations were skipped by the syncmetadata service, so no more migrations were generated for relation fields. We wanted to fix this. ## Test This PR adds unit tests for the `createIndexMigration` utility in the workspace migration builder. The tests cover: - Creating index migrations for simple fields (e.g., text fields) - Creating index migrations for relation fields (ensuring correct column naming, e.g., `authorId` for the `author` objectmetadataname) ## Excluded The delete index on relation does not need the column names so i don't think i needed to work on this method. I might be wrong. ## Checklist - [x] Added/updated unit tests for index migration creation - [x] Verified correct handling of simple and relation fields - [x] Ensured all tests pass --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -69,46 +69,30 @@ export class StandardIndexFactory {
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
workspaceIndexMetadataArgsCollection
|
||||
.map((workspaceIndexMetadataArgs) => {
|
||||
const objectMetadata =
|
||||
originalStandardObjectMetadataMap[workspaceEntity.nameSingular];
|
||||
return workspaceIndexMetadataArgsCollection.map(
|
||||
(workspaceIndexMetadataArgs) => {
|
||||
const objectMetadata =
|
||||
originalStandardObjectMetadataMap[workspaceEntity.nameSingular];
|
||||
|
||||
if (!objectMetadata) {
|
||||
throw new Error(
|
||||
`Object metadata not found for ${workspaceEntity.nameSingular}`,
|
||||
);
|
||||
}
|
||||
|
||||
const indexMetadata: PartialIndexMetadata = {
|
||||
workspaceId: context.workspaceId,
|
||||
objectMetadataId: objectMetadata.id,
|
||||
name: workspaceIndexMetadataArgs.name,
|
||||
columns: workspaceIndexMetadataArgs.columns,
|
||||
isUnique: workspaceIndexMetadataArgs.isUnique,
|
||||
isCustom: false,
|
||||
indexWhereClause: workspaceIndexMetadataArgs.whereClause,
|
||||
indexType: workspaceIndexMetadataArgs.type,
|
||||
};
|
||||
|
||||
return indexMetadata;
|
||||
})
|
||||
// TODO: remove this filter when we have a way to handle index on relations
|
||||
.filter((workspaceIndexMetadataArgs) => {
|
||||
const objectMetadata =
|
||||
originalStandardObjectMetadataMap[workspaceEntity.nameSingular];
|
||||
|
||||
const hasAllFields = workspaceIndexMetadataArgs.columns.every(
|
||||
(expectedField) => {
|
||||
return objectMetadata.fields.some(
|
||||
(field) => field.name === expectedField,
|
||||
);
|
||||
},
|
||||
if (!objectMetadata) {
|
||||
throw new Error(
|
||||
`Object metadata not found for ${workspaceEntity.nameSingular}`,
|
||||
);
|
||||
}
|
||||
|
||||
return hasAllFields;
|
||||
})
|
||||
const indexMetadata: PartialIndexMetadata = {
|
||||
workspaceId: context.workspaceId,
|
||||
objectMetadataId: objectMetadata.id,
|
||||
name: workspaceIndexMetadataArgs.name,
|
||||
columns: workspaceIndexMetadataArgs.columns,
|
||||
isUnique: workspaceIndexMetadataArgs.isUnique,
|
||||
isCustom: false,
|
||||
indexWhereClause: workspaceIndexMetadataArgs.whereClause,
|
||||
indexType: workspaceIndexMetadataArgs.type,
|
||||
};
|
||||
|
||||
return indexMetadata;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user