Fix 'name' column wrongly added in standard objects (#7428)
## Context Name shouldn't be added to all tables, especially standard objects because they already have their own labelIdentifierFieldMetadata specified in the workspace-entity schema. This PR removes this column from the "base" list of columns to add when creating a new object/table and moves it to the object-metadata service that is, as of today, only used for custom objects. Also had to modify the migration-runner to handle column creation in a table creation migration (this was available in the migration definition already but was not doing anything) This also fixes an issue in standard objects that already have a "name" field defined with a different field type, this is even more important when the said field is a composite field. For example people already has a FULL_NAME name field which clashes with the default TEXT name field meaning it was only creating 1 field metadata for 'name' but 3 columns were created: `name, nameFirstName, nameLastName`. This inconsistency with metadata (which is our source of truth everywhere) brought some issues (lately, converting back typeorm response to gql (including composition) was broken).
This commit is contained in:
@ -49,8 +49,10 @@ import { generateMigrationName } from 'src/engine/metadata-modules/workspace-mig
|
||||
import {
|
||||
WorkspaceMigrationColumnActionType,
|
||||
WorkspaceMigrationColumnDrop,
|
||||
WorkspaceMigrationTableAction,
|
||||
WorkspaceMigrationTableActionType,
|
||||
} from 'src/engine/metadata-modules/workspace-migration/workspace-migration.entity';
|
||||
import { WorkspaceMigrationFactory } from 'src/engine/metadata-modules/workspace-migration/workspace-migration.factory';
|
||||
import { WorkspaceMigrationService } from 'src/engine/metadata-modules/workspace-migration/workspace-migration.service';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { computeObjectTargetTable } from 'src/engine/utils/compute-object-target-table.util';
|
||||
@ -103,6 +105,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
private readonly workspaceMigrationRunnerService: WorkspaceMigrationRunnerService,
|
||||
private readonly workspaceMetadataVersionService: WorkspaceMetadataVersionService,
|
||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||
private readonly workspaceMigrationFactory: WorkspaceMigrationFactory,
|
||||
) {
|
||||
super(objectMetadataRepository);
|
||||
}
|
||||
@ -563,9 +566,39 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
objectMetadataInput.primaryKeyFieldMetadataSettings,
|
||||
);
|
||||
|
||||
return this.workspaceMigrationService.createCustomMigration(
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(`create-${createdObjectMetadata.nameSingular}`),
|
||||
createdObjectMetadata.workspaceId,
|
||||
[
|
||||
{
|
||||
name: computeObjectTargetTable(createdObjectMetadata),
|
||||
action: WorkspaceMigrationTableActionType.CREATE,
|
||||
} satisfies WorkspaceMigrationTableAction,
|
||||
],
|
||||
);
|
||||
|
||||
for (const fieldMetadata of createdObjectMetadata.fields) {
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(`create-${fieldMetadata.name}`),
|
||||
createdObjectMetadata.workspaceId,
|
||||
[
|
||||
{
|
||||
name: computeObjectTargetTable(createdObjectMetadata),
|
||||
action: WorkspaceMigrationTableActionType.ALTER,
|
||||
columns: this.workspaceMigrationFactory.createColumnActions(
|
||||
WorkspaceMigrationColumnActionType.CREATE,
|
||||
fieldMetadata,
|
||||
),
|
||||
},
|
||||
] satisfies WorkspaceMigrationTableAction[],
|
||||
);
|
||||
}
|
||||
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(
|
||||
`create-${createdObjectMetadata.nameSingular}-relations`,
|
||||
),
|
||||
createdObjectMetadata.workspaceId,
|
||||
buildMigrationsForCustomObjectRelations(
|
||||
createdObjectMetadata,
|
||||
activityTargetObjectMetadata,
|
||||
@ -611,7 +644,9 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
}
|
||||
|
||||
this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(`create-${createdObjectMetadata.nameSingular}`),
|
||||
generateMigrationName(
|
||||
`update-${createdObjectMetadata.nameSingular}-add-searchVector`,
|
||||
),
|
||||
createdObjectMetadata.workspaceId,
|
||||
[
|
||||
{
|
||||
|
||||
@ -18,10 +18,6 @@ export const buildMigrationsForCustomObjectRelations = (
|
||||
noteTargetObjectMetadata: ObjectMetadataEntity,
|
||||
taskTargetObjectMetadata: ObjectMetadataEntity,
|
||||
): WorkspaceMigrationTableAction[] => [
|
||||
{
|
||||
name: computeObjectTargetTable(createdObjectMetadata),
|
||||
action: WorkspaceMigrationTableActionType.CREATE,
|
||||
} satisfies WorkspaceMigrationTableAction,
|
||||
// Add activity target relation
|
||||
{
|
||||
name: computeObjectTargetTable(activityTargetObjectMetadata),
|
||||
|
||||
Reference in New Issue
Block a user