7a1e699fc8
# Introduction related to https://github.com/twentyhq/core-team-issues/issues/1833 In this PR we're starting the sync-metadata and standardIds deprecation by introducing `twenty-standard` application that will regroup every standard object such as company and opportunities. But also the `custom-workspace-application` which is an app created at the same time as a workspace and that will regroup everything configure within the workspace ( custom objects fields etc ) ## What's done On both new workspace and seeded workspace creation: - Creating a custom workspace app - Creating a twenty standard app - Refactored the seed core schema and workspace creation to be run within a transaction in order to handle circular dependency foreignkey requirements ( which is deferred for app toward workspace ) - Updated workspace entity to have a custom workspace relation ( nullable for the moment until we implem an upgrade command to handle retro comp ) - Integration testing on user, workspace creation deletion and expected default apps creation - ~~Soft deleted user on `deleteUser`~~ Done by marie and rebased on it ## What's next - Update seeder to propagate the `twenty-standard` workspace `applicationId` to every standard synchronized entities ( cheap and fast iteration through the about to be deprecated sync-metadata as an easy way to synchronize standards metadata entities ). - Update seeder to propagate the `custom-workspace-application` workspace `applicationId` to anything custom ( `pets` and `rockets` ) - Prepend `custom-workspace-application` `applicationId` to every metadata API operations ( create a specific cache etc ) - Upgrade command on all existing workspace to create a custom app and associate its applicationId to any existing custom entities - Make `universalIdentifier` and `applicationId` required for any syncable entity
114 lines
4.8 KiB
TypeScript
114 lines
4.8 KiB
TypeScript
import { msg } from '@lingui/core/macro';
|
|
import { RelationOnDeleteAction } 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 { 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';
|
|
import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator';
|
|
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
|
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
|
|
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
|
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
|
import { TASK_TARGET_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
|
import { STANDARD_OBJECT_ICONS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-icons';
|
|
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
|
import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity';
|
|
import { OpportunityWorkspaceEntity } from 'src/modules/opportunity/standard-objects/opportunity.workspace-entity';
|
|
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
|
import { TaskWorkspaceEntity } from 'src/modules/task/standard-objects/task.workspace-entity';
|
|
|
|
@WorkspaceEntity({
|
|
standardId: STANDARD_OBJECT_IDS.taskTarget,
|
|
|
|
namePlural: 'taskTargets',
|
|
labelSingular: msg`Task Target`,
|
|
labelPlural: msg`Task Targets`,
|
|
description: msg`A task target`,
|
|
icon: STANDARD_OBJECT_ICONS.taskTarget,
|
|
})
|
|
@WorkspaceIsSystem()
|
|
export class TaskTargetWorkspaceEntity extends BaseWorkspaceEntity {
|
|
@WorkspaceRelation({
|
|
standardId: TASK_TARGET_STANDARD_FIELD_IDS.task,
|
|
type: RelationType.MANY_TO_ONE,
|
|
label: msg`Task`,
|
|
description: msg`TaskTarget task`,
|
|
icon: 'IconCheckbox',
|
|
inverseSideTarget: () => TaskWorkspaceEntity,
|
|
inverseSideFieldKey: 'taskTargets',
|
|
onDelete: RelationOnDeleteAction.SET_NULL,
|
|
})
|
|
@WorkspaceIsNullable()
|
|
task: Relation<TaskWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('task')
|
|
taskId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: TASK_TARGET_STANDARD_FIELD_IDS.person,
|
|
type: RelationType.MANY_TO_ONE,
|
|
label: msg`Person`,
|
|
description: msg`TaskTarget person`,
|
|
icon: 'IconUser',
|
|
inverseSideTarget: () => PersonWorkspaceEntity,
|
|
inverseSideFieldKey: 'taskTargets',
|
|
onDelete: RelationOnDeleteAction.CASCADE,
|
|
})
|
|
@WorkspaceIsNullable()
|
|
person: Relation<PersonWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('person')
|
|
personId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: TASK_TARGET_STANDARD_FIELD_IDS.company,
|
|
type: RelationType.MANY_TO_ONE,
|
|
label: msg`Company`,
|
|
description: msg`TaskTarget company`,
|
|
icon: 'IconBuildingSkyscraper',
|
|
inverseSideTarget: () => CompanyWorkspaceEntity,
|
|
inverseSideFieldKey: 'taskTargets',
|
|
onDelete: RelationOnDeleteAction.CASCADE,
|
|
})
|
|
@WorkspaceIsNullable()
|
|
company: Relation<CompanyWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('company')
|
|
companyId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: TASK_TARGET_STANDARD_FIELD_IDS.opportunity,
|
|
type: RelationType.MANY_TO_ONE,
|
|
label: msg`Opportunity`,
|
|
description: msg`TaskTarget opportunity`,
|
|
icon: 'IconTargetArrow',
|
|
inverseSideTarget: () => OpportunityWorkspaceEntity,
|
|
inverseSideFieldKey: 'taskTargets',
|
|
onDelete: RelationOnDeleteAction.CASCADE,
|
|
})
|
|
@WorkspaceIsNullable()
|
|
opportunity: Relation<OpportunityWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('opportunity')
|
|
opportunityId: string | null;
|
|
|
|
@WorkspaceDynamicRelation({
|
|
type: RelationType.MANY_TO_ONE,
|
|
argsFactory: (oppositeObjectMetadata) => ({
|
|
standardId: TASK_TARGET_STANDARD_FIELD_IDS.custom,
|
|
name: oppositeObjectMetadata.nameSingular,
|
|
label: oppositeObjectMetadata.labelSingular,
|
|
description: `TaskTarget ${oppositeObjectMetadata.labelSingular}`,
|
|
joinColumn: `${oppositeObjectMetadata.nameSingular}Id`,
|
|
icon: 'IconBuildingSkyscraper',
|
|
}),
|
|
inverseSideTarget: () => CustomWorkspaceEntity,
|
|
inverseSideFieldKey: 'taskTargets',
|
|
onDelete: RelationOnDeleteAction.CASCADE,
|
|
})
|
|
custom: Relation<CustomWorkspaceEntity>;
|
|
}
|