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:
Jérémy M
2025-04-22 19:01:39 +02:00
committed by GitHub
parent de1489aabb
commit cc29c25176
160 changed files with 3247 additions and 711 deletions

View File

@ -1,9 +1,9 @@
import { msg } from '@lingui/core/macro';
import { FieldMetadataType } from 'twenty-shared/types';
import { RelationType } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-type.interface';
import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator';
import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
@ -86,7 +86,7 @@ export class AuditLogWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: AUDIT_LOGS_STANDARD_FIELD_IDS.workspaceMember,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Workspace Member`,
description: msg`Event workspace member`,
icon: 'IconCircleUser',

View File

@ -1,9 +1,9 @@
import { msg } from '@lingui/core/macro';
import { FieldMetadataType } from 'twenty-shared/types';
import { RelationType } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-type.interface';
import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
import { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
import { WorkspaceDynamicRelation } from 'src/engine/twenty-orm/decorators/workspace-dynamic-relation.decorator';
@ -100,7 +100,7 @@ export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
// Who made the action
@WorkspaceRelation({
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.workspaceMember,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Workspace Member`,
description: msg`Event workspace member`,
icon: 'IconCircleUser',
@ -115,7 +115,7 @@ export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.person,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Person`,
description: msg`Event person`,
icon: 'IconUser',
@ -130,7 +130,7 @@ export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.company,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Company`,
description: msg`Event company`,
icon: 'IconBuildingSkyscraper',
@ -145,7 +145,7 @@ export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.opportunity,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Opportunity`,
description: msg`Event opportunity`,
icon: 'IconTargetArrow',
@ -160,7 +160,7 @@ export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.note,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Note`,
description: msg`Event note`,
icon: 'IconTargetArrow',
@ -175,7 +175,7 @@ export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.task,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Task`,
description: msg`Event task`,
icon: 'IconTargetArrow',
@ -190,7 +190,7 @@ export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.workflow,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Workflow`,
description: msg`Event workflow`,
icon: 'IconTargetArrow',
@ -205,7 +205,7 @@ export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.workflowVersion,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`WorkflowVersion`,
description: msg`Event workflow version`,
icon: 'IconTargetArrow',
@ -220,7 +220,7 @@ export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.workflowRun,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Workflow Run`,
description: msg`Event workflow run`,
icon: 'IconTargetArrow',
@ -234,7 +234,7 @@ export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
workflowRunId: string | null;
@WorkspaceDynamicRelation({
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
argsFactory: (oppositeObjectMetadata) => ({
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.custom,
name: oppositeObjectMetadata.nameSingular,