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,6 +1,8 @@
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';
@ -9,10 +11,6 @@ import { AddressMetadata } from 'src/engine/metadata-modules/field-metadata/comp
import { CurrencyMetadata } from 'src/engine/metadata-modules/field-metadata/composite-types/currency.composite-type';
import { LinksMetadata } from 'src/engine/metadata-modules/field-metadata/composite-types/links.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 { WorkspaceDuplicateCriteria } from 'src/engine/twenty-orm/decorators/workspace-duplicate-criteria.decorator';
import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator';
@ -164,7 +162,7 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
// Relations
@WorkspaceRelation({
standardId: COMPANY_STANDARD_FIELD_IDS.people,
type: RelationMetadataType.ONE_TO_MANY,
type: RelationType.ONE_TO_MANY,
label: msg`People`,
description: msg`People linked to the company.`,
icon: 'IconUsers',
@ -176,7 +174,7 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: COMPANY_STANDARD_FIELD_IDS.accountOwner,
type: RelationMetadataType.MANY_TO_ONE,
type: RelationType.MANY_TO_ONE,
label: msg`Account Owner`,
description: msg`Your team member responsible for managing the company account`,
icon: 'IconUserCircle',
@ -192,7 +190,7 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: COMPANY_STANDARD_FIELD_IDS.taskTargets,
type: RelationMetadataType.ONE_TO_MANY,
type: RelationType.ONE_TO_MANY,
label: msg`Tasks`,
description: msg`Tasks tied to the company`,
icon: 'IconCheckbox',
@ -203,7 +201,7 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: COMPANY_STANDARD_FIELD_IDS.noteTargets,
type: RelationMetadataType.ONE_TO_MANY,
type: RelationType.ONE_TO_MANY,
label: msg`Notes`,
description: msg`Notes tied to the company`,
icon: 'IconNotes',
@ -214,7 +212,7 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: COMPANY_STANDARD_FIELD_IDS.opportunities,
type: RelationMetadataType.ONE_TO_MANY,
type: RelationType.ONE_TO_MANY,
label: msg`Opportunities`,
description: msg`Opportunities linked to the company.`,
icon: 'IconTargetArrow',
@ -226,7 +224,7 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: COMPANY_STANDARD_FIELD_IDS.favorites,
type: RelationMetadataType.ONE_TO_MANY,
type: RelationType.ONE_TO_MANY,
label: msg`Favorites`,
description: msg`Favorites linked to the company`,
icon: 'IconHeart',
@ -239,7 +237,7 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: COMPANY_STANDARD_FIELD_IDS.attachments,
type: RelationMetadataType.ONE_TO_MANY,
type: RelationType.ONE_TO_MANY,
label: msg`Attachments`,
description: msg`Attachments linked to the company`,
icon: 'IconFileImport',
@ -251,7 +249,7 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: COMPANY_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 company`,
icon: 'IconIconTimelineEvent',