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 { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
import { WorkspaceDynamicRelation } from 'src/engine/twenty-orm/decorators/workspace-dynamic-relation.decorator';
@ -63,7 +63,7 @@ export class AttachmentWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: ATTACHMENT_STANDARD_FIELD_IDS.author,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Author`,
description: msg`Attachment author`,
icon: 'IconCircleUser',
@ -78,7 +78,7 @@ export class AttachmentWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: ATTACHMENT_STANDARD_FIELD_IDS.task,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Task`,
description: msg`Attachment task`,
icon: 'IconNotes',
@ -93,7 +93,7 @@ export class AttachmentWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: ATTACHMENT_STANDARD_FIELD_IDS.note,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Note`,
description: msg`Attachment note`,
icon: 'IconNotes',
@ -108,7 +108,7 @@ export class AttachmentWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: ATTACHMENT_STANDARD_FIELD_IDS.person,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Person`,
description: msg`Attachment person`,
icon: 'IconUser',
@ -123,7 +123,7 @@ export class AttachmentWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: ATTACHMENT_STANDARD_FIELD_IDS.company,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Company`,
description: msg`Attachment company`,
icon: 'IconBuildingSkyscraper',
@ -138,7 +138,7 @@ export class AttachmentWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: ATTACHMENT_STANDARD_FIELD_IDS.opportunity,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Opportunity`,
description: msg`Attachment opportunity`,
icon: 'IconBuildingSkyscraper',
@ -152,7 +152,7 @@ export class AttachmentWorkspaceEntity extends BaseWorkspaceEntity {
opportunityId: string | null;
@WorkspaceDynamicRelation({
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
argsFactory: (oppositeObjectMetadata) => ({
standardId: ATTACHMENT_STANDARD_FIELD_IDS.custom,
name: oppositeObjectMetadata.nameSingular,