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,8 +1,8 @@
import { msg } from '@lingui/core/macro';
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';
@ -31,7 +31,7 @@ import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/perso
export class NoteTargetWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: NOTE_TARGET_STANDARD_FIELD_IDS.note,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Note`,
description: msg`NoteTarget note`,
icon: 'IconNotes',
@ -46,7 +46,7 @@ export class NoteTargetWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: NOTE_TARGET_STANDARD_FIELD_IDS.person,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Person`,
description: msg`NoteTarget person`,
icon: 'IconUser',
@ -61,7 +61,7 @@ export class NoteTargetWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: NOTE_TARGET_STANDARD_FIELD_IDS.company,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Company`,
description: msg`NoteTarget company`,
icon: 'IconBuildingSkyscraper',
@ -76,7 +76,7 @@ export class NoteTargetWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: NOTE_TARGET_STANDARD_FIELD_IDS.opportunity,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Opportunity`,
description: msg`NoteTarget opportunity`,
icon: 'IconTargetArrow',
@ -90,7 +90,7 @@ export class NoteTargetWorkspaceEntity extends BaseWorkspaceEntity {
opportunityId: string | null;
@WorkspaceDynamicRelation({
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
argsFactory: (oppositeObjectMetadata) => ({
standardId: NOTE_TARGET_STANDARD_FIELD_IDS.custom,
name: oppositeObjectMetadata.nameSingular,

View File

@ -1,16 +1,14 @@
import { msg } from '@lingui/core/macro';
import { FieldMetadataType } from 'twenty-shared/types';
import { RelationOnDeleteAction } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-on-delete-action.interface';
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 { SEARCH_VECTOR_FIELD } from 'src/engine/metadata-modules/constants/search-vector-field.constants';
import { ActorMetadata } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
import { RichTextV2Metadata } from 'src/engine/metadata-modules/field-metadata/composite-types/rich-text-v2.composite-type';
import { IndexType } from 'src/engine/metadata-modules/index-metadata/index-metadata.entity';
import {
RelationMetadataType,
RelationOnDeleteAction,
} 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 { WorkspaceFieldIndex } from 'src/engine/twenty-orm/decorators/workspace-field-index.decorator';
@ -105,7 +103,7 @@ export class NoteWorkspaceEntity extends BaseWorkspaceEntity {
label: msg`Relations`,
description: msg`Note targets`,
icon: 'IconArrowUpRight',
type: RelationMetadataType.ONE_TO_MANY,
type: RelationType.ONE_TO_MANY,
inverseSideTarget: () => NoteTargetWorkspaceEntity,
onDelete: RelationOnDeleteAction.SET_NULL,
})
@ -117,7 +115,7 @@ export class NoteWorkspaceEntity extends BaseWorkspaceEntity {
label: msg`Attachments`,
description: msg`Note attachments`,
icon: 'IconFileImport',
type: RelationMetadataType.ONE_TO_MANY,
type: RelationType.ONE_TO_MANY,
inverseSideTarget: () => AttachmentWorkspaceEntity,
onDelete: RelationOnDeleteAction.SET_NULL,
})
@ -126,7 +124,7 @@ export class NoteWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: NOTE_STANDARD_FIELD_IDS.timelineActivities,
type: RelationMetadataType.ONE_TO_MANY,
type: RelationType.ONE_TO_MANY,
label: msg`Timeline Activities`,
description: msg`Timeline Activities linked to the note.`,
icon: 'IconTimelineEvent',
@ -138,7 +136,7 @@ export class NoteWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: NOTE_STANDARD_FIELD_IDS.favorites,
type: RelationMetadataType.ONE_TO_MANY,
type: RelationType.ONE_TO_MANY,
label: msg`Favorites`,
description: msg`Favorites linked to the note`,
icon: 'IconHeart',