feat: new relation sync-metadata, twenty-orm, create/update (#10217)
Fix https://github.com/twentyhq/core-team-issues/issues/330#issue-2827026606 and https://github.com/twentyhq/core-team-issues/issues/327#issue-2827001814 What this PR does when `isNewRelationEnabled` is set to `true`: - [x] Drop the creation of the foreign key as a `FieldMetadata` - [x] Stop creating `RelationMetadata` - [x] Properly fill `FieldMetadata` of type `RELATION` during the sync command - [x] Use new relation settings in TwentyORM - [x] Properly create `FieldMetadata` relations when we create a new object - [x] Handle `database:reset` with new relations --------- Co-authored-by: Charles Bochet <charles@twenty.com> Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
This commit is contained in:
@ -18,10 +18,10 @@ import {
|
||||
RelationDirection,
|
||||
deduceRelationDirection,
|
||||
} from 'src/engine/utils/deduce-relation-direction.util';
|
||||
import { isFieldMetadataOfType } from 'src/engine/utils/is-field-metadata-of-type.util';
|
||||
import { isFieldMetadataEntityOfType } from 'src/engine/utils/is-field-metadata-of-type.util';
|
||||
|
||||
@Command({
|
||||
name: 'upgrade:0-51:migrate-relations-to-field-metadata',
|
||||
name: 'upgrade:0-52:migrate-relations-to-field-metadata',
|
||||
description: 'Migrate relations to field metadata',
|
||||
})
|
||||
export class MigrateRelationsToFieldMetadataCommand extends ActiveOrSuspendedWorkspacesMigrationCommandRunner {
|
||||
@ -64,13 +64,13 @@ export class MigrateRelationsToFieldMetadataCommand extends ActiveOrSuspendedWor
|
||||
|
||||
const joinColumnFieldMetadataCollection = fieldMetadataCollection.filter(
|
||||
(fieldMetadata) =>
|
||||
isFieldMetadataOfType(fieldMetadata, FieldMetadataType.UUID),
|
||||
isFieldMetadataEntityOfType(fieldMetadata, FieldMetadataType.UUID),
|
||||
// TODO: Fix this, it's working in other places but not here
|
||||
) as FieldMetadataEntity<FieldMetadataType.UUID>[];
|
||||
|
||||
const fieldMetadataToUpdateCollection = fieldMetadataCollection
|
||||
.filter((fieldMetadata) =>
|
||||
isFieldMetadataOfType(fieldMetadata, FieldMetadataType.RELATION),
|
||||
isFieldMetadataEntityOfType(fieldMetadata, FieldMetadataType.RELATION),
|
||||
)
|
||||
.map((fieldMetadata) =>
|
||||
this.updateRelationFieldMetadata(
|
||||
@ -2,6 +2,7 @@ import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { BackfillWorkflowNextStepIdsCommand } from 'src/database/commands/upgrade-version-command/0-52/0-52-backfill-workflow-next-step-ids.command';
|
||||
import { MigrateRelationsToFieldMetadataCommand } from 'src/database/commands/upgrade-version-command/0-52/0-52-migrate-relations-to-field-metadata.command';
|
||||
import { UpgradeDateAndDateTimeFieldsSettingsJsonCommand } from 'src/database/commands/upgrade-version-command/0-52/0-52-upgrade-settings-field';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
@ -20,10 +21,12 @@ import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/works
|
||||
providers: [
|
||||
BackfillWorkflowNextStepIdsCommand,
|
||||
UpgradeDateAndDateTimeFieldsSettingsJsonCommand,
|
||||
MigrateRelationsToFieldMetadataCommand,
|
||||
],
|
||||
exports: [
|
||||
BackfillWorkflowNextStepIdsCommand,
|
||||
UpgradeDateAndDateTimeFieldsSettingsJsonCommand,
|
||||
MigrateRelationsToFieldMetadataCommand,
|
||||
],
|
||||
})
|
||||
export class V0_52_UpgradeVersionCommandModule {}
|
||||
|
||||
@ -17,6 +17,7 @@ import { UpdateDefaultViewRecordOpeningOnWorkflowObjectsCommand } from 'src/data
|
||||
import { InitializePermissionsCommand } from 'src/database/commands/upgrade-version-command/0-44/0-44-initialize-permissions.command';
|
||||
import { UpdateViewAggregateOperationsCommand } from 'src/database/commands/upgrade-version-command/0-44/0-44-update-view-aggregate-operations.command';
|
||||
import { UpgradeCreatedByEnumCommand } from 'src/database/commands/upgrade-version-command/0-51/0-51-update-workflow-trigger-type-enum.command';
|
||||
import { MigrateRelationsToFieldMetadataCommand } from 'src/database/commands/upgrade-version-command/0-52/0-52-migrate-relations-to-field-metadata.command';
|
||||
import { UpgradeDateAndDateTimeFieldsSettingsJsonCommand } from 'src/database/commands/upgrade-version-command/0-52/0-52-upgrade-settings-field';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
@ -58,6 +59,7 @@ export class UpgradeCommand extends UpgradeCommandRunner {
|
||||
|
||||
// 0.52 Commands
|
||||
protected readonly upgradeDateAndDateTimeFieldsSettingsJsonCommand: UpgradeDateAndDateTimeFieldsSettingsJsonCommand,
|
||||
protected readonly migrateRelationsToFieldMetadataCommand: MigrateRelationsToFieldMetadataCommand,
|
||||
) {
|
||||
super(
|
||||
workspaceRepository,
|
||||
@ -99,6 +101,7 @@ export class UpgradeCommand extends UpgradeCommandRunner {
|
||||
const _commands_052: VersionCommands = {
|
||||
beforeSyncMetadata: [
|
||||
this.upgradeDateAndDateTimeFieldsSettingsJsonCommand,
|
||||
this.migrateRelationsToFieldMetadataCommand,
|
||||
],
|
||||
afterSyncMetadata: [],
|
||||
};
|
||||
|
||||
@ -63,7 +63,7 @@ export const seedFeatureFlags = async (
|
||||
{
|
||||
key: FeatureFlagKey.IsNewRelationEnabled,
|
||||
workspaceId: workspaceId,
|
||||
value: false,
|
||||
value: true,
|
||||
},
|
||||
])
|
||||
.execute();
|
||||
|
||||
Reference in New Issue
Block a user