From d532f22fbbf3154eaddf61d5e6aa1cf06a1789df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20M?= Date: Thu, 21 Dec 2023 19:15:05 +0100 Subject: [PATCH] feat: migration can be applied on a specific schema & some enhancements (#2998) * fix: remove old metadata seed files * feat: wip standard to core relation * fix: lint * fix: merge * fix: remove debug files * feat: add feature flag for core object metadata * fix: remove debug * feat: always disable the standard core relation * fix: missing feature flag * fix: remove debug * fix: feature flag doesn't seems to disable relation * fix: delete .vscode folder, change this in another PR * Update packages/twenty-server/src/workspace/workspace-sync-metadata/reflective-metadata.factory.ts Co-authored-by: Weiko * Update packages/twenty-server/src/workspace/workspace-sync-metadata/reflective-metadata.factory.ts Co-authored-by: Weiko * Update packages/twenty-server/src/workspace/workspace-sync-metadata/workspace-sync.metadata.service.ts Co-authored-by: Weiko * fix: remove optional fields from metadata entities * fix: renamed variable * fix: put back CursorScalarType * fix: delete test command * fix: remove unused workspace standard migration command * fix: drop core object metadata declaration * fix: rename variable * fix: drop creation of core datasource * fix: remove feature flag * fix: drop support of standard to core relations * feat: add user email field on workspace-member standard object * fix: update seed accordingly * fix: missing remove command file * fix: datasource label should remain nullable * fix: better asserts * Remove unused code * Remove unused code --------- Co-authored-by: Weiko Co-authored-by: Charles Bochet --- packages/twenty-server/@types/common.d.ts | 10 +- packages/twenty-server/src/command.module.ts | 2 - .../core/user/dtos/workspace-member.dto.ts | 12 +- .../src/core/user/services/user.service.ts | 4 +- .../src/core/user/user.entity.ts | 6 +- .../src/core/user/user.resolver.ts | 6 +- .../typeorm-seeds/metadata/data-source.ts | 33 -- .../field-metadata/activity-target.ts | 201 --------- .../metadata/field-metadata/activity.ts | 341 ---------------- .../metadata/field-metadata/api-key.ts | 156 ------- .../metadata/field-metadata/attachment.ts | 304 -------------- .../metadata/field-metadata/comment.ts | 187 --------- .../metadata/field-metadata/company.ts | 382 ------------------ .../metadata/field-metadata/favorite.ts | 225 ----------- .../metadata/field-metadata/opportunity.ts | 295 -------------- .../metadata/field-metadata/person.ts | 379 ----------------- .../metadata/field-metadata/pipeline-step.ts | 177 -------- .../metadata/field-metadata/view-field.ts | 209 ---------- .../metadata/field-metadata/view-filter.ts | 209 ---------- .../metadata/field-metadata/view-sort.ts | 171 -------- .../metadata/field-metadata/view.ts | 207 ---------- .../metadata/field-metadata/webhook.ts | 137 ------- .../field-metadata/workspace-member.ts | 300 -------------- .../database/typeorm-seeds/metadata/index.ts | 58 --- .../typeorm-seeds/metadata/object-metadata.ts | 306 -------------- .../metadata/relation-metadata/activity.ts | 56 --- .../metadata/relation-metadata/company.ts | 74 ---- .../metadata/relation-metadata/person.ts | 73 ---- .../relation-metadata/pipeline-step.ts | 38 -- .../metadata/relation-metadata/view.ts | 56 --- .../relation-metadata/workspace-member.ts | 87 ---- .../workspace/workspaceMember.ts | 4 + .../data-source/data-source.entity.ts | 8 +- .../field-metadata/field-metadata.service.ts | 2 + .../object-metadata.service.ts | 24 +- .../relation-metadata.service.ts | 6 + .../migrations/1697618009-addCompanyTable.ts | 84 ---- .../migrations/1697618011-addViewTable.ts | 34 -- .../1697618012-addViewFieldTable.ts | 51 --- .../1697618013-addViewFilterTable.ts | 51 --- .../migrations/1697618014-addViewSortTable.ts | 39 -- .../1697618015-addActivityTargetTable.ts | 32 -- .../migrations/1697618016-addActivityTable.ts | 60 --- .../migrations/1697618017-addApiKeyTable.ts | 33 -- .../1697618018-addAttachmentTable.ts | 55 --- .../migrations/1697618019-addCommentTable.ts | 33 -- .../migrations/1697618020-addFavoriteTable.ts | 38 -- .../1697618021-addOpportunityTable.ts | 58 --- .../migrations/1697618022-addPersonTable.ts | 88 ---- .../1697618023-addPipelineStepTable.ts | 35 -- .../migrations/1697618024-addWebhookTable.ts | 29 -- .../1697618026-addWorspaceMemberTable.ts | 51 --- .../1697618027-addCompanyRelations.ts | 19 - .../1697618028-addAttachmentRelations.ts | 37 -- .../1697618029-addPersonRelations.ts | 19 - .../1697618030-addFavoriteRelations.ts | 31 -- .../1697618031-addOpportunityRelations.ts | 37 -- .../1697618032-addActivityTargetRelations.ts | 31 -- .../1697618033-addActivityRelations.ts | 25 -- .../1697618034-addCommentRelations.ts | 25 -- .../1697618035-addConnectedAccount.ts | 47 --- .../standard-migrations.ts | 56 --- .../workspace-migration.entity.ts | 2 + .../workspace-migration.service.ts | 38 -- .../twenty-server/src/utils/typed-reflect.ts | 71 ++++ .../run-workspace-migrations.command.ts | 45 --- ...kspace-migration-runner-commands.module.ts | 12 - .../workspace-migration-runner.service.ts | 19 +- .../factories/relation-field-alias.factory.ts | 8 +- .../graphql-types/scalars/index.ts | 2 +- .../decorators/field-metadata.decorator.ts | 82 ++++ .../decorators/gate.decorator.ts | 13 + .../decorators/is-nullable.decorator.ts | 7 + .../decorators/is-system.decorator.ts | 11 + .../decorators/metadata.decorator.ts | 210 ---------- .../decorators/object-metadata.decorator.ts | 29 ++ .../decorators/relation-metadata.decorator.ts | 35 ++ .../interfaces/gate-decorator.interface.ts | 3 + .../interfaces/mapped-metadata.interface.ts | 19 + .../partial-field-metadata.interface.ts | 6 + .../partial-object-metadata.interface.ts | 8 + .../reflect-field-metadata.interface.ts | 32 ++ .../reflect-object-metadata.interface.ts | 17 + .../reflect-relation-metadata.interface.ts | 18 + ...rser.ts => reflective-metadata.factory.ts} | 104 ++--- .../activity-target.object-metadata.ts | 10 +- .../activity.object-metadata.ts | 12 +- .../api-key.object-metadata.ts | 10 +- .../attachment.object-metadata.ts | 10 +- .../standard-objects/base.object-metadata.ts | 10 +- .../comment.object-metadata.ts | 8 +- .../company.object-metadata.ts | 10 +- .../connected-account.object-metadata.ts | 14 +- .../favorite.object-metadata.ts | 10 +- .../message-channel.object-metadata.ts | 14 +- .../message-recipient.object-metadata.ts | 12 +- .../message-thread.object-metadata.ts | 14 +- .../message.object-metadata.ts | 14 +- .../opportunity.object-metadata.ts | 8 +- .../person.object-metadata.ts | 14 +- .../pipeline-step.object-metadata.ts | 12 +- .../view-field.object-metadata.ts | 10 +- .../view-filter.object-metadata.ts | 14 +- .../view-sort.object-metadata.ts | 11 +- .../standard-objects/view.object-metadata.ts | 15 +- .../webhook.object-metadata.ts | 8 +- .../workspace-member.object-metadata.ts | 22 +- ...vert-class-to-object-metadata-name.util.ts | 12 + .../utils/is-gate-and-not-enabled.util.ts | 10 + .../utils/sync-metadata.util.ts | 59 ++- .../workspace-sync-metadata.module.ts | 3 +- .../workspace-sync.metadata.service.ts | 115 ++++-- 112 files changed, 714 insertions(+), 6381 deletions(-) delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/data-source.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/activity-target.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/activity.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/api-key.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/attachment.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/comment.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/company.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/favorite.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/opportunity.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/person.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/pipeline-step.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-field.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-filter.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-sort.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/webhook.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/workspace-member.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/index.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/object-metadata.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/activity.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/company.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/person.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/pipeline-step.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/view.ts delete mode 100644 packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/workspace-member.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618009-addCompanyTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618011-addViewTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618012-addViewFieldTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618013-addViewFilterTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618014-addViewSortTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618015-addActivityTargetTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618016-addActivityTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618017-addApiKeyTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618018-addAttachmentTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618019-addCommentTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618020-addFavoriteTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618021-addOpportunityTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618022-addPersonTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618023-addPipelineStepTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618024-addWebhookTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618026-addWorspaceMemberTable.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618027-addCompanyRelations.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618028-addAttachmentRelations.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618029-addPersonRelations.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618030-addFavoriteRelations.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618031-addOpportunityRelations.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618032-addActivityTargetRelations.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618033-addActivityRelations.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618034-addCommentRelations.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/migrations/1697618035-addConnectedAccount.ts delete mode 100644 packages/twenty-server/src/metadata/workspace-migration/standard-migrations.ts create mode 100644 packages/twenty-server/src/utils/typed-reflect.ts delete mode 100644 packages/twenty-server/src/workspace/workspace-migration-runner/commands/run-workspace-migrations.command.ts delete mode 100644 packages/twenty-server/src/workspace/workspace-migration-runner/commands/workspace-migration-runner-commands.module.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/gate.decorator.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/is-system.decorator.ts delete mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/metadata.decorator.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/gate-decorator.interface.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/mapped-metadata.interface.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/partial-field-metadata.interface.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/partial-object-metadata.interface.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-field-metadata.interface.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-object-metadata.interface.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-relation-metadata.interface.ts rename packages/twenty-server/src/workspace/workspace-sync-metadata/{utils/metadata.parser.ts => reflective-metadata.factory.ts} (58%) create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util.ts create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/utils/is-gate-and-not-enabled.util.ts diff --git a/packages/twenty-server/@types/common.d.ts b/packages/twenty-server/@types/common.d.ts index f203e1ce92..c4fc63d673 100644 --- a/packages/twenty-server/@types/common.d.ts +++ b/packages/twenty-server/@types/common.d.ts @@ -1,5 +1,5 @@ -type DeepPartial = T extends object - ? { - [P in keyof T]?: DeepPartial; - } - : T; +type DeepPartial = { + [K in keyof T]?: T[K] extends Array + ? Array> + : DeepPartial; +}; diff --git a/packages/twenty-server/src/command.module.ts b/packages/twenty-server/src/command.module.ts index 738e562e99..1772a3de56 100644 --- a/packages/twenty-server/src/command.module.ts +++ b/packages/twenty-server/src/command.module.ts @@ -6,12 +6,10 @@ import { FetchWorkspaceMessagesCommandsModule } from 'src/workspace/messaging/co import { AppModule } from './app.module'; import { WorkspaceSyncMetadataCommandsModule } from './workspace/workspace-sync-metadata/commands/workspace-sync-metadata-commands.module'; -import { WorkspaceMigrationRunnerCommandsModule } from './workspace/workspace-migration-runner/commands/workspace-migration-runner-commands.module'; @Module({ imports: [ AppModule, - WorkspaceMigrationRunnerCommandsModule, WorkspaceSyncMetadataCommandsModule, DatabaseCommandModule, FetchWorkspaceMessagesCommandsModule, diff --git a/packages/twenty-server/src/core/user/dtos/workspace-member.dto.ts b/packages/twenty-server/src/core/user/dtos/workspace-member.dto.ts index e0a268be76..a3c069c724 100644 --- a/packages/twenty-server/src/core/user/dtos/workspace-member.dto.ts +++ b/packages/twenty-server/src/core/user/dtos/workspace-member.dto.ts @@ -2,8 +2,8 @@ import { Field, ID, ObjectType } from '@nestjs/graphql'; import { IDField } from '@ptc-org/nestjs-query-graphql'; -@ObjectType('UserWorkspaceMemberName') -export class UserWorkspaceMemberName { +@ObjectType('FullName') +export class FullName { @Field({ nullable: false }) firstName: string; @@ -11,13 +11,13 @@ export class UserWorkspaceMemberName { lastName: string; } -@ObjectType('UserWorkspaceMember') -export class UserWorkspaceMember { +@ObjectType('WorkspaceMember') +export class WorkspaceMember { @IDField(() => ID) id: string; - @Field(() => UserWorkspaceMemberName) - name: UserWorkspaceMemberName; + @Field(() => FullName) + name: FullName; @Field({ nullable: false }) colorScheme: string; diff --git a/packages/twenty-server/src/core/user/services/user.service.ts b/packages/twenty-server/src/core/user/services/user.service.ts index 0feb56bad8..7817c56a50 100644 --- a/packages/twenty-server/src/core/user/services/user.service.ts +++ b/packages/twenty-server/src/core/user/services/user.service.ts @@ -5,7 +5,7 @@ import { Repository } from 'typeorm'; import { assert } from 'src/utils/assert'; import { User } from 'src/core/user/user.entity'; -import { UserWorkspaceMember } from 'src/core/user/dtos/workspace-member.dto'; +import { WorkspaceMember } from 'src/core/user/dtos/workspace-member.dto'; import { DataSourceService } from 'src/metadata/data-source/data-source.service'; import { TypeORMService } from 'src/database/typeorm/typeorm.service'; @@ -35,7 +35,7 @@ export class UserService extends TypeOrmQueryService { assert(workspaceMembers.length === 1, 'WorkspaceMember not found'); - const userWorkspaceMember = new UserWorkspaceMember(); + const userWorkspaceMember = new WorkspaceMember(); userWorkspaceMember.id = workspaceMembers[0].id; userWorkspaceMember.colorScheme = workspaceMembers[0].colorScheme; diff --git a/packages/twenty-server/src/core/user/user.entity.ts b/packages/twenty-server/src/core/user/user.entity.ts index 602521bc3a..808df5de97 100644 --- a/packages/twenty-server/src/core/user/user.entity.ts +++ b/packages/twenty-server/src/core/user/user.entity.ts @@ -13,7 +13,7 @@ import { IDField } from '@ptc-org/nestjs-query-graphql'; import { RefreshToken } from 'src/core/refresh-token/refresh-token.entity'; import { Workspace } from 'src/core/workspace/workspace.entity'; -import { UserWorkspaceMember } from 'src/core/user/dtos/workspace-member.dto'; +import { WorkspaceMember } from 'src/core/user/dtos/workspace-member.dto'; @Entity({ name: 'user', schema: 'core' }) @ObjectType('User') @@ -73,6 +73,6 @@ export class User { }) refreshTokens: RefreshToken[]; - @Field(() => UserWorkspaceMember, { nullable: false }) - workspaceMember: UserWorkspaceMember; + @Field(() => WorkspaceMember, { nullable: false }) + workspaceMember: WorkspaceMember; } diff --git a/packages/twenty-server/src/core/user/user.resolver.ts b/packages/twenty-server/src/core/user/user.resolver.ts index 5be793e141..ef7ec59ada 100644 --- a/packages/twenty-server/src/core/user/user.resolver.ts +++ b/packages/twenty-server/src/core/user/user.resolver.ts @@ -22,7 +22,7 @@ import { FileUploadService } from 'src/core/file/services/file-upload.service'; import { assert } from 'src/utils/assert'; import { JwtAuthGuard } from 'src/guards/jwt.auth.guard'; import { User } from 'src/core/user/user.entity'; -import { UserWorkspaceMember } from 'src/core/user/dtos/workspace-member.dto'; +import { WorkspaceMember } from 'src/core/user/dtos/workspace-member.dto'; import { UserService } from './services/user.service'; @@ -54,10 +54,10 @@ export class UserResolver { return user; } - @ResolveField(() => UserWorkspaceMember, { + @ResolveField(() => WorkspaceMember, { nullable: false, }) - async workspaceMember(@Parent() user: User): Promise { + async workspaceMember(@Parent() user: User): Promise { return this.userService.loadWorkspaceMember(user); } diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/data-source.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/data-source.ts deleted file mode 100644 index 48bc6d181a..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/data-source.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -export const SeedWorkspaceSchemaName = 'workspace_1wgvd1injqtife6y4rvfbu3h5'; - -const tableName = 'dataSource'; - -export const SeedDataSourceId = '20202020-7f63-47a9-b1b3-6c7290ca9fb1'; - -export const seedDataSource = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource.query( - `CREATE SCHEMA IF NOT EXISTS ${SeedWorkspaceSchemaName}`, - ); - - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${tableName}`, ['id', 'schema', 'type', 'workspaceId']) - .orIgnore() - .values([ - { - id: SeedDataSourceId, - schema: SeedWorkspaceSchemaName, - type: 'postgres', - workspaceId: SeedWorkspaceId, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/activity-target.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/activity-target.ts deleted file mode 100644 index db80467d50..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/activity-target.ts +++ /dev/null @@ -1,201 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedActivityTargetFieldMetadataIds { - Id = '20202020-7db7-4dac-8093-ea0a12e9466f', - CreatedAt = '20202020-585f-48fa-a4b6-97cf7f86315e', - UpdatedAt = '20202020-4cf0-4478-8c68-62a855622a99', - - Activity = '20202020-cb21-42c9-bba8-347f7cb02b84', - ActivityForeignKey = '20202020-2b1a-4c6a-9c0a-1b9f5b7c9b1a', - Person = '20202020-e56c-43e6-8fce-5619d8c2293a', - PersonForeignKey = '20202020-4c5d-4b5e-8d6e-3b2a4d5f6a7b', - Company = '20202020-9408-4cc0-9fe1-51467edb530b', - CompanyForeignKey = '20202020-9408-4cc0-9fe1-51467edb530c', -} - -export const seedActivityTargetFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedActivityTargetFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.ActivityTarget, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedActivityTargetFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.ActivityTarget, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedActivityTargetFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.ActivityTarget, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Relationships - { - id: SeedActivityTargetFieldMetadataIds.Activity, - objectMetadataId: SeedObjectMetadataIds.ActivityTarget, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'activity', - label: 'Activity', - targetColumnMap: {}, - description: 'ActivityTarget activity', - icon: 'IconNotes', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedActivityTargetFieldMetadataIds.ActivityForeignKey, - objectMetadataId: SeedObjectMetadataIds.ActivityTarget, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'activityId', - label: 'Activity id (foreign key)', - targetColumnMap: {}, - description: 'ActivityTarget activity id foreign key', - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedActivityTargetFieldMetadataIds.Person, - objectMetadataId: SeedObjectMetadataIds.ActivityTarget, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'person', - label: 'Person', - targetColumnMap: {}, - description: 'ActivityTarget person', - icon: 'IconUser', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedActivityTargetFieldMetadataIds.PersonForeignKey, - objectMetadataId: SeedObjectMetadataIds.ActivityTarget, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'personId', - label: 'Person id (foreign key)', - targetColumnMap: {}, - description: 'ActivityTarget person id foreign key', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedActivityTargetFieldMetadataIds.Company, - objectMetadataId: SeedObjectMetadataIds.ActivityTarget, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'company', - label: 'Company', - targetColumnMap: {}, - description: 'ActivityTarget company', - icon: 'IconBuildingSkyscraper', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedActivityTargetFieldMetadataIds.CompanyForeignKey, - objectMetadataId: SeedObjectMetadataIds.ActivityTarget, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'companyId', - label: 'Company id (foreign key)', - targetColumnMap: {}, - description: 'ActivityTarget company id foreign key', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/activity.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/activity.ts deleted file mode 100644 index dd48cb84f9..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/activity.ts +++ /dev/null @@ -1,341 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedActivityFieldMetadataIds { - Id = '20202020-f695-419c-b928-c488323d6df3', - CreatedAt = '20202020-65a2-4d9c-b640-bac54007a14d', - UpdatedAt = '20202020-88df-4202-bf82-6a06c6963280', - - Title = '20202020-2584-4797-95a8-5cc90d48c040', - Body = '20202020-aff0-4961-be8a-0e5c2598b9a6', - Type = '20202020-a243-4b94-a4b4-25705af86be2', - ReminderAt = '20202020-cd46-44f4-bf22-b0aa20d009da', - DueAt = '20202020-20e1-4366-b386-750bdca2dfe3', - CompletedAt = '20202020-0924-48f0-a8c2-d2dd4e2098e2', - - ActivityTargets = '20202020-ec1d-4ffe-8bd2-a85c23ae0037', - Comments = '20202020-c85c-47f2-bbe4-6b36c26f9247', - Attachments = '20202020-9755-43a8-b621-f94df0f6b839', - Author = '20202020-3acb-46bb-b993-0dc49fa2a48c', - AuthorForeignKey = '20202020-3acb-46bb-b993-0dc49fa2a48d', - Assignee = '20202020-4694-4ec6-9084-8d932ebb3065', - AssigneeForeignKey = '20202020-4694-4ec6-9084-8d932ebb3066', -} - -export const seedActivityFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedActivityFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedActivityFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedActivityFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Primary identifier - { - id: SeedActivityFieldMetadataIds.Title, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'title', - label: 'Title', - targetColumnMap: { - value: 'title', - }, - description: 'Activity title', - icon: 'IconNotes', - isNullable: true, - isSystem: false, - defaultValue: { value: '' }, - }, - - // Scalar fields - { - id: SeedActivityFieldMetadataIds.Body, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'body', - label: 'Body', - targetColumnMap: { - value: 'body', - }, - description: 'Activity body', - icon: 'IconList', - isNullable: true, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedActivityFieldMetadataIds.Type, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'type', - label: 'Type', - targetColumnMap: { - value: 'type', - }, - description: 'Activity type', - icon: 'IconCheckbox', - isNullable: false, - isSystem: false, - defaultValue: { value: 'Note' }, - }, - { - id: SeedActivityFieldMetadataIds.ReminderAt, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'reminderAt', - label: 'Reminder Date', - targetColumnMap: { - value: 'reminderAt', - }, - description: 'Activity reminder date', - icon: 'IconCalendarEvent', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedActivityFieldMetadataIds.DueAt, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'dueAt', - label: 'Due Date', - targetColumnMap: { - value: 'dueAt', - }, - description: 'Activity due date', - icon: 'IconCalendarEvent', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedActivityFieldMetadataIds.CompletedAt, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'completedAt', - label: 'Completion Date', - targetColumnMap: { - value: 'completedAt', - }, - description: 'Activity completion date', - icon: 'IconCheck', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - - // Relationships - { - id: SeedActivityFieldMetadataIds.ActivityTargets, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'activityTargets', - label: 'Targets', - targetColumnMap: {}, - description: 'Activity targets', - icon: 'IconCheckbox', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedActivityFieldMetadataIds.Attachments, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'attachments', - label: 'Attachments', - targetColumnMap: {}, - description: 'Activity attachments', - icon: 'IconFileImport', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedActivityFieldMetadataIds.Comments, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'comments', - label: 'Comments', - targetColumnMap: {}, - description: 'Activity comments', - icon: 'IconComment', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedActivityFieldMetadataIds.Author, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'author', - label: 'Author', - targetColumnMap: { - value: 'authorId', - }, - description: - 'Activity author. This is the person who created the activity', - icon: 'IconUserCircle', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedActivityFieldMetadataIds.AuthorForeignKey, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'authorId', - label: 'Author id (foreign key)', - targetColumnMap: {}, - description: 'Activity author id foreign key', - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedActivityFieldMetadataIds.Assignee, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'assignee', - label: 'Assignee', - targetColumnMap: {}, - description: - 'Acitivity assignee. This is the workspace member assigned to the activity ', - icon: 'IconUserCircle', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedActivityFieldMetadataIds.AssigneeForeignKey, - objectMetadataId: SeedObjectMetadataIds.Activity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'assigneeId', - label: 'Assignee id (foreign key)', - targetColumnMap: {}, - description: 'Acitivity assignee id foreign key', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/api-key.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/api-key.ts deleted file mode 100644 index fc6b499ce8..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/api-key.ts +++ /dev/null @@ -1,156 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedApiKeyFieldMetadataIds { - Id = '20202020-7222-45ee-b5c4-c30eba68566f', - CreatedAt = '20202020-ecd6-479f-8368-5032fdee43b3', - UpdatedAt = '20202020-435c-4133-93c0-df5709d1694d', - - Name = '20202020-1dfa-4ef3-8d19-51e82c28677a', - ExpiresAt = '20202020-a092-41e2-940e-e17cd0403aa7', - RevokedAt = '20202020-da41-436e-8498-b1a99c23b275', -} - -export const seedApiKeyFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedApiKeyFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.ApiKey, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedApiKeyFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.ApiKey, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedApiKeyFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.ApiKey, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Scalar fields - { - id: SeedApiKeyFieldMetadataIds.Name, - objectMetadataId: SeedObjectMetadataIds.ApiKey, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'name', - label: 'Name', - targetColumnMap: { - value: 'name', - }, - description: 'ApiKey name', - icon: 'IconLink', - isNullable: true, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedApiKeyFieldMetadataIds.ExpiresAt, - objectMetadataId: SeedObjectMetadataIds.ApiKey, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'expiresAt', - label: 'Expiration date', - targetColumnMap: { - value: 'expiresAt', - }, - description: 'ApiKey expiration date', - icon: 'IconCalendar', - isNullable: false, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedApiKeyFieldMetadataIds.RevokedAt, - objectMetadataId: SeedObjectMetadataIds.ApiKey, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'revokedAt', - label: 'Revocation date', - targetColumnMap: { - value: 'revokedAt', - }, - description: 'ApiKey revocation date', - icon: 'IconCalendar', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/attachment.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/attachment.ts deleted file mode 100644 index 5d1c56ad4a..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/attachment.ts +++ /dev/null @@ -1,304 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedAttachmentFieldMetadataIds { - Id = '20202020-0544-432b-8f96-84c4d6a94d50', - CreatedAt = '20202020-839b-4cbb-a1be-1a0cb85524a4', - UpdatedAt = '20202020-7f29-490d-a3e1-9c3015524057', - - Name = '20202020-5683-4c80-8590-255321ece692', - FullPath = '20202020-bb72-4644-b255-afb4ebb83b66', - Type = '20202020-8dfa-492f-92d1-56d5fb18cbb7', - - Author = '20202020-7831-43c2-827f-bc78289b7398', - AuthorForeignKey = '20202020-7831-43c2-827f-bc78289b7399', - Activity = '20202020-f5a9-46ec-b39a-eda906f00804', - ActivityForeignKey = '20202020-f5a9-46ec-b39a-eda906f00805', - Person = '20202020-f67c-4cc5-893c-c6b615527473', - PersonForeignKey = '20202020-f67c-4cc5-893c-c6b615527474', - Company = '20202020-5463-4d03-9124-1775b9b7f955', - CompanyForeignKey = '20202020-5463-4d03-9124-1775b9b7f956', -} - -export const seedAttachmentFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedAttachmentFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedAttachmentFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedAttachmentFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Primary Identifier - { - id: SeedAttachmentFieldMetadataIds.Name, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'name', - label: 'Name', - targetColumnMap: { - value: 'name', - }, - description: 'Attachment name', - icon: 'IconFileUpload', - isNullable: false, - isSystem: false, - defaultValue: { value: '' }, - }, - // Scalar fields - { - id: SeedAttachmentFieldMetadataIds.FullPath, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'fullPath', - label: 'Full path', - targetColumnMap: { - value: 'fullPath', - }, - description: 'Attachment full path', - icon: 'IconLink', - isNullable: false, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedAttachmentFieldMetadataIds.Type, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'type', - label: 'Type', - targetColumnMap: { - value: 'type', - }, - description: 'Attachment type', - icon: 'IconList', - isNullable: false, - isSystem: false, - defaultValue: { value: '' }, - }, - - // Relationships - { - id: SeedAttachmentFieldMetadataIds.Author, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'author', - label: 'Author', - targetColumnMap: { - value: 'authorId', - }, - description: 'Attachment author', - icon: 'IconCircleUser', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedAttachmentFieldMetadataIds.AuthorForeignKey, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'authorId', - label: 'Author id (foreign key)', - targetColumnMap: {}, - description: 'Attachment author id foreign key', - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedAttachmentFieldMetadataIds.Activity, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'activity', - label: 'Activity', - targetColumnMap: { - value: 'activityId', - }, - description: 'Attachment activity', - icon: 'IconNotes', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedAttachmentFieldMetadataIds.ActivityForeignKey, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'activityId', - label: 'Activity id (foreign key)', - targetColumnMap: {}, - description: 'Attachment activity id foreign key', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedAttachmentFieldMetadataIds.Person, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'person', - label: 'Person', - targetColumnMap: { - value: 'personId', - }, - description: 'Attachment person', - icon: 'IconUser', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedAttachmentFieldMetadataIds.PersonForeignKey, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'personId', - label: 'Person id (foreign key)', - targetColumnMap: {}, - description: 'Attachment person id foreign key', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedAttachmentFieldMetadataIds.Company, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'company', - label: 'Company', - targetColumnMap: { - value: 'companyId', - }, - description: 'Attachment company', - icon: 'IconBuildingSkyscraper', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedAttachmentFieldMetadataIds.CompanyForeignKey, - objectMetadataId: SeedObjectMetadataIds.Attachment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'companyId', - label: 'Company id (foreign key)', - targetColumnMap: {}, - description: 'Attachment company id foreign key', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/comment.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/comment.ts deleted file mode 100644 index effd3b3369..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/comment.ts +++ /dev/null @@ -1,187 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedCommentFieldMetadataIds { - Id = '20202020-2899-42fa-ba07-1f4dad7ae28f', - CreatedAt = '20202020-88fd-4db2-9fcb-b5f4f5955cf2', - UpdatedAt = '20202020-63dd-4426-abad-9973fece49ed', - - Body = '20202020-354b-4f10-9425-fa3eb8fddc51', - Author = '20202020-2c70-40c2-bba6-893780b25d41', - AuthorForeignKey = '20202021-2c70-40c2-bba6-893780b25d42', - Activity = '20202020-a9ac-4294-9462-db0f690da906', - ActivityForeignKey = '20202021-a9ac-4294-9462-db0f690da907', -} - -export const seedCommentFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedCommentFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.Comment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedCommentFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.Comment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedCommentFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.Comment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Scalar fields - { - id: SeedCommentFieldMetadataIds.Body, - objectMetadataId: SeedObjectMetadataIds.Comment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'body', - label: 'Body', - targetColumnMap: { - value: 'body', - }, - description: 'Comment body', - icon: 'IconLink', - isNullable: false, - isSystem: false, - defaultValue: { value: '' }, - }, - // Relationships - { - id: SeedCommentFieldMetadataIds.Author, - objectMetadataId: SeedObjectMetadataIds.Comment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'author', - label: 'Author', - targetColumnMap: {}, - description: 'Comment author', - icon: 'IconCircleUser', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedCommentFieldMetadataIds.AuthorForeignKey, - objectMetadataId: SeedObjectMetadataIds.Comment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'authorId', - label: 'Author id (foreign key)', - targetColumnMap: {}, - description: 'Comment author id foreign key', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedCommentFieldMetadataIds.Activity, - objectMetadataId: SeedObjectMetadataIds.Comment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'activity', - label: 'Activity', - targetColumnMap: {}, - description: 'Comment activity', - icon: 'IconNotes', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedCommentFieldMetadataIds.ActivityForeignKey, - objectMetadataId: SeedObjectMetadataIds.Comment, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'activityId', - label: 'Activity id (foreign key)', - targetColumnMap: {}, - description: 'Activity id foreign key', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/company.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/company.ts deleted file mode 100644 index 0b55c5ac58..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/company.ts +++ /dev/null @@ -1,382 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedCompanyFieldMetadataIds { - Id = '20202020-8169-44a3-9e0b-6bad1ac50f87', - CreatedAt = '20202020-4dc2-47c9-bb15-6e6f19ba9e46', - UpdatedAt = '20202020-64b8-41bf-a01c-be6a806e8b70', - - Name = '20202020-6d30-4111-9f40-b4301906fd3c', - - DomainName = '20202020-5e4e-4007-a630-8a2617914889', - Address = '20202020-ad10-4117-a039-3f04b7a5f939', - Employees = '20202020-7fbd-41ad-b64d-25a15ff62f04', - LinkedinLink = '20202020-a61d-4b78-b998-3fd88b4f73a1', - XUrl = '20202020-46e3-479a-b8f4-77137c74daa6', - AnnualRecurringRevenue = '20202020-4a5a-466f-92d9-c3870d9502a9', - IdealCustomerProfile = '20202020-9e9f-4235-98b2-c76f3e2d281e', - - People = '20202020-68b4-4c8e-af19-738eba2a42a5', - AccountOwner = '20202020-0739-495d-8e70-c0807f6b2268', - AccountOwnerForeignKey = '20202020-0b9e-4b9e-8b0a-5b0b5b0b5b0b', - ActivityTargets = '20202020-4a2e-4b41-8562-279963e8947e', - Opportunities = '20202020-e3fc-46ff-b552-3e757843f06e', - Favorites = '20202020-e7c8-4771-8cc4-ce0e8c36a3c0', - Attachments = '20202020-61af-4ffd-b79b-baed6db8ad11', -} - -export const seedCompanyFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedCompanyFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedCompanyFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: false, - defaultValue: { type: 'now' }, - }, - { - id: SeedCompanyFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Main Identifier - { - id: SeedCompanyFieldMetadataIds.Name, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'name', - label: 'Name', - targetColumnMap: { - value: 'name', - }, - description: 'The company name', - icon: 'IconBuildingSkyscraper', - isNullable: true, - isSystem: false, - defaultValue: { value: '' }, - }, - // Scalar Fields - { - id: SeedCompanyFieldMetadataIds.DomainName, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'domainName', - label: 'Domain Name', - targetColumnMap: { - value: 'domainName', - }, - description: - 'The company website URL. We use this url to fetch the company icon', - icon: 'IconLink', - isNullable: true, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedCompanyFieldMetadataIds.Address, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'address', - label: 'Address', - targetColumnMap: { - value: 'address', - }, - description: 'The company address', - icon: 'IconMap', - isNullable: true, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedCompanyFieldMetadataIds.Employees, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.NUMBER, - name: 'employees', - label: 'Employees', - targetColumnMap: { - value: 'employees', - }, - description: 'Number of employees in the company', - icon: 'IconUsers', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedCompanyFieldMetadataIds.LinkedinLink, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.LINK, - name: 'linkedinLink', - label: 'Linkedin', - targetColumnMap: { - label: 'linkedinLinkLabel', - url: 'linkedinLinkUrl', - }, - description: 'The company Linkedin account', - icon: 'IconBrandLinkedin', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedCompanyFieldMetadataIds.XUrl, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.LINK, - name: 'xLink', - label: 'X', - targetColumnMap: { - label: 'xLinkLabel', - url: 'xLinkUrl', - }, - description: 'The company Twitter/X account', - icon: 'IconBrandX', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedCompanyFieldMetadataIds.AnnualRecurringRevenue, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.CURRENCY, - name: 'annualRecurringRevenue', - label: 'ARR', - targetColumnMap: { - amountMicros: 'annualRecurringRevenueAmountMicros', - currencyCode: 'annualRecurringRevenueCurrencyCode', - }, - description: - 'Annual Recurring Revenue: The actual or estimated annual revenue of the company', - icon: 'IconMoneybag', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedCompanyFieldMetadataIds.IdealCustomerProfile, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.BOOLEAN, - name: 'idealCustomerProfile', - label: 'ICP', - targetColumnMap: { - value: 'idealCustomerProfile', - }, - description: - 'Ideal Customer Profile: Indicates whether the company is the most suitable and valuable customer for you', - icon: 'IconTarget', - isNullable: true, - isSystem: false, - defaultValue: false, - }, - - // Relationships - { - id: SeedCompanyFieldMetadataIds.People, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'people', - label: 'People', - targetColumnMap: {}, - description: 'People linked to the company.', - icon: 'IconUsers', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedCompanyFieldMetadataIds.AccountOwner, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'accountOwner', - label: 'Account Owner', - targetColumnMap: {}, - description: - 'Your team member responsible for managing the company account', - icon: 'IconUserCircle', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedCompanyFieldMetadataIds.AccountOwnerForeignKey, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'accountOwnerId', - label: 'Account Owner ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for account owner', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedCompanyFieldMetadataIds.ActivityTargets, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'activityTargets', - label: 'Activities', - targetColumnMap: {}, - description: 'Activities tied to the company', - icon: 'IconCheckbox', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedCompanyFieldMetadataIds.Opportunities, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'opportunities', - label: 'Opportunities', - targetColumnMap: {}, - description: 'Opportunities linked to the company.', - icon: 'IconTargetArrow', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedCompanyFieldMetadataIds.Favorites, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'favorites', - label: 'Favorites', - targetColumnMap: {}, - description: 'Favorites linked to the company', - icon: 'IconHeart', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedCompanyFieldMetadataIds.Attachments, - objectMetadataId: SeedObjectMetadataIds.Company, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'attachments', - label: 'Attachments', - targetColumnMap: {}, - description: 'Attachments linked to the company.', - icon: 'IconFileImport', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/favorite.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/favorite.ts deleted file mode 100644 index 10f39f8d0e..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/favorite.ts +++ /dev/null @@ -1,225 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedFavoriteFieldMetadataIds { - Id = '20202020-7d1d-46c7-8c09-8e8c73e30042', - CreatedAt = '20202020-a0f4-443c-a63d-2776a842d024', - UpdatedAt = '20202020-273a-41bc-babf-f58f0b2ba2ec', - - Position = '20202020-dd6d-4f67-94aa-22cc83eb0a2e', - - WorkspaceMember = '20202020-1138-4e93-bbff-917a68161abf', - WorkspaceMemberForeignKey = '20202020-0f4c-4b9a-9b9a-917a68161a4f', - Person = '20202020-0876-4735-8974-ff4d51aafa07', - PersonForeignKey = '20202020-0876-4735-9473-ff4d51aa4e7b', - Company = '20202020-09e1-4384-ae3e-39e7956396ff', - CompanyForeignKey = '20202020-09e1-4384-ae3e-45e79563d528', -} - -export const seedFavoriteFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedFavoriteFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.Favorite, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedFavoriteFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.Favorite, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedFavoriteFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.Favorite, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Scalar fields - { - id: SeedFavoriteFieldMetadataIds.Position, - objectMetadataId: SeedObjectMetadataIds.Favorite, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.NUMBER, - name: 'position', - label: 'Position', - targetColumnMap: { - value: 'position', - }, - description: 'Favorite position', - icon: 'IconList', - isNullable: false, - isSystem: false, - defaultValue: { value: 0 }, - }, - - // Relationships - { - id: SeedFavoriteFieldMetadataIds.WorkspaceMember, - objectMetadataId: SeedObjectMetadataIds.Favorite, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'workspaceMember', - label: 'Workspace Member', - targetColumnMap: {}, - description: 'Favorite workspace member', - icon: 'IconCircleUser', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedFavoriteFieldMetadataIds.WorkspaceMemberForeignKey, - objectMetadataId: SeedObjectMetadataIds.Favorite, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'workspaceMemberId', - label: 'Workspace Member ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for workspace member', - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedFavoriteFieldMetadataIds.Person, - objectMetadataId: SeedObjectMetadataIds.Favorite, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'person', - label: 'Person', - targetColumnMap: { - value: 'personId', - }, - description: 'Favorite person', - icon: 'IconUser', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedFavoriteFieldMetadataIds.PersonForeignKey, - objectMetadataId: SeedObjectMetadataIds.Favorite, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'personId', - label: 'Person ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for person', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedFavoriteFieldMetadataIds.Company, - objectMetadataId: SeedObjectMetadataIds.Favorite, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'company', - label: 'Company', - targetColumnMap: {}, - description: 'Favorite company', - icon: 'IconBuildingSkyscraper', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedFavoriteFieldMetadataIds.CompanyForeignKey, - objectMetadataId: SeedObjectMetadataIds.Favorite, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'companyId', - label: 'Company ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for company', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/opportunity.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/opportunity.ts deleted file mode 100644 index 9dce3226c9..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/opportunity.ts +++ /dev/null @@ -1,295 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedOpportunityFieldMetadataIds { - Id = '20202020-16ef-476c-8eac-d439b84024cb', - CreatedAt = '20202020-a39d-4ea9-994f-28d1ebd15904', - UpdatedAt = '20202020-437b-4fd7-98bd-00cb91204329', - - Amount = '20202020-8c1f-4c83-9a89-7843e586564d', - CloseDate = '20202020-de52-4e7b-a298-db7a7553500f', - Probability = '20202020-3b9c-4e58-a3d2-c617d3b596b1', - - PipelineStep = '20202020-0a2e-4676-8011-3fdb2c30c258', - PipelineStepForeignKey = '20202020-0a2e-4676-8011-3fdb2c30d7f8', - PointOfContact = '20202020-618e-42da-b3c3-bcd7af76e355', - PointOfContactForeignKey = '20202020-618e-42da-b3c3-bcd7af76e4c2', - Company = '20202020-31d5-4af5-b016-c61c1c265706', - CompanyForeignKey = '20202020-31d5-4af5-b016-c61c1c2657b9', - Person = '20202020-0655-41df-b938-15d71e589307', - PersonForeignKey = '20202020-0655-41df-b938-15d71e589d3e', -} - -export const seedOpportunityFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedOpportunityFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedOpportunityFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: false, - defaultValue: { type: 'now' }, - }, - { - id: SeedOpportunityFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Scalar fields - { - id: SeedOpportunityFieldMetadataIds.Amount, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.CURRENCY, - name: 'amount', - label: 'Amount', - targetColumnMap: { - amountMicros: 'amountAmountMicros', - currencyCode: 'amountCurrencyCode', - }, - description: 'Opportunity amount', - icon: 'IconCurrencyDollar', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedOpportunityFieldMetadataIds.CloseDate, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'closeDate', - label: 'Close date', - targetColumnMap: { - value: 'closeDate', - }, - description: 'Opportunity close date', - icon: 'IconCalendarEvent', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedOpportunityFieldMetadataIds.Probability, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'probability', - label: 'Probability', - targetColumnMap: { - value: 'probability', - }, - description: 'Opportunity probability', - icon: 'IconProgressCheck', - isNullable: true, - isSystem: false, - defaultValue: { value: '0' }, - }, - // Relationships - { - id: SeedOpportunityFieldMetadataIds.PipelineStep, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'pipelineStep', - label: 'Pipeline Step', - targetColumnMap: {}, - description: 'Opportunity pipeline step', - icon: 'IconKanban', - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedOpportunityFieldMetadataIds.PipelineStepForeignKey, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'pipelineStepId', - label: 'Pipeline Step ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for pipeline step', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedOpportunityFieldMetadataIds.PointOfContact, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'pointOfContact', - label: 'Point of Contact', - targetColumnMap: {}, - description: 'Opportunity point of contact', - icon: 'IconUser', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedOpportunityFieldMetadataIds.PointOfContactForeignKey, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'pointOfContactId', - label: 'Point of Contact ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for point of contact', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedOpportunityFieldMetadataIds.Person, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'person', - label: 'Person', - targetColumnMap: {}, - description: 'Opportunity person', - icon: 'IconUser', - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedOpportunityFieldMetadataIds.PersonForeignKey, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'personId', - label: 'Person ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for person', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedOpportunityFieldMetadataIds.Company, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'company', - label: 'Company', - targetColumnMap: {}, - description: 'Opportunity company', - icon: 'IconBuildingSkyscraper', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedOpportunityFieldMetadataIds.CompanyForeignKey, - objectMetadataId: SeedObjectMetadataIds.Opportunity, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'companyId', - label: 'Company ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for company', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/person.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/person.ts deleted file mode 100644 index fa9090c4fe..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/person.ts +++ /dev/null @@ -1,379 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedPersonFieldMetadataIds { - Id = '20202020-03cd-4cd0-9afc-92077b69f24f', - CreatedAt = '20202020-bec0-4cf0-bf1c-8b2ed21f027a', - UpdatedAt = '20202020-2bf4-42b8-8718-a3e852bfa6a6', - - Name = '20202020-9b56-4888-bfe3-f6f59aa999e3', - - Email = '20202020-8a96-4e4b-86fd-ea126530e0c1', - LinkedinLink = '20202020-dcf6-445a-b543-37e55de43c25', - XLink = '20202020-a3a7-4f63-9303-10226f6055be', - JobTitle = '20202020-3b86-413e-ab56-0ebd1a583ff3', - Phone = '20202020-486f-45f9-bbdf-aac18b1831c0', - City = '20202020-78f8-4b4c-90ff-86adf77590f5', - AvatarUrl = '20202020-bb05-45cb-aa2a-71b58d49dd23', - - Company = '20202020-64e1-4080-b6ad-db03c3809885', - CompanyForeignKey = '20202020-64e1-4080-b6ad-db03c3809f8b', - ContactForOpportunities = '20202020-2c2e-418e-ba2d-d28434ff02a6', - Opportunities = '20202020-6bc4-4905-a9d3-4f8d616a19e1', - ActivityTargets = '20202020-f285-4115-a46c-116522986b29', - Favorites = '20202020-6268-4165-8774-9aaf45db2b25', - Attachments = '20202020-5883-4bb3-a308-65271901a1d4', -} - -export const seedPersonFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedPersonFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedPersonFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: false, - defaultValue: { type: 'now' }, - }, - { - id: SeedPersonFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Main Identifier - { - id: SeedPersonFieldMetadataIds.Name, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.FULL_NAME, - name: 'name', - label: 'Name', - targetColumnMap: { - firstName: 'nameFirstName', - lastName: 'nameLastName', - }, - description: 'Contact’s name', - icon: 'IconUser', - isNullable: true, - isSystem: false, - defaultValue: { firstName: '', lastName: '' }, - }, - - // Scalar Fields - { - id: SeedPersonFieldMetadataIds.Email, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.EMAIL, - name: 'email', - label: 'Email', - targetColumnMap: { - value: 'email', - }, - description: 'Contact’s Email', - icon: 'IconMail', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedPersonFieldMetadataIds.LinkedinLink, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.LINK, - name: 'linkedinLink', - label: 'Linkedin', - targetColumnMap: { - label: 'linkedinLinkLabel', - url: 'linkedinLinkUrl', - }, - description: 'Contact’s Linkedin account', - icon: 'IconBrandLinkedin', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedPersonFieldMetadataIds.XLink, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.LINK, - name: 'xLink', - label: 'X', - targetColumnMap: { - label: 'xLinkLabel', - url: 'xLinkUrl', - }, - description: 'Contact’s X/Twitter account', - icon: 'IconBrandX', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedPersonFieldMetadataIds.JobTitle, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'jobTitle', - label: 'Job Title', - targetColumnMap: { - value: 'jobTitle', - }, - description: 'Contact’s job title', - icon: 'IconBriefcase', - isNullable: true, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedPersonFieldMetadataIds.Phone, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'phone', - label: 'Phone', - targetColumnMap: { - value: 'phone', - }, - description: 'Contact’s phone number', - icon: 'IconPhone', - isNullable: true, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedPersonFieldMetadataIds.City, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'city', - label: 'City', - targetColumnMap: { - value: 'city', - }, - description: 'Contact’s city', - icon: 'IconMap', - isNullable: true, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedPersonFieldMetadataIds.AvatarUrl, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'avatarUrl', - label: 'Avatar', - targetColumnMap: { - value: 'avatarUrl', - }, - description: 'Contact’s avatar', - icon: 'IconFileUpload', - isNullable: true, - isSystem: true, - defaultValue: { value: '' }, - }, - - // Relationships - { - id: SeedPersonFieldMetadataIds.Company, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'company', - label: 'Company', - targetColumnMap: {}, - description: 'Contact’s company', - icon: 'IconBuildingSkyscraper', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedPersonFieldMetadataIds.CompanyForeignKey, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'companyId', - label: 'Company ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for company', - icon: undefined, - isNullable: true, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedPersonFieldMetadataIds.ContactForOpportunities, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'pointOfContactForOpportunities', - label: 'POC for Opportunities', - targetColumnMap: {}, - description: 'Point of Contact for Opportuniites', - icon: 'IconTargetArrow', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedPersonFieldMetadataIds.ActivityTargets, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'activityTargets', - label: 'Activities', - targetColumnMap: {}, - description: 'Activities tied to the contact', - icon: 'IconCheckbox', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedPersonFieldMetadataIds.Opportunities, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'opportunities', - label: 'Opportunities', - targetColumnMap: {}, - description: 'Opportunities linked to the contact.', - icon: 'IconTargetArrow', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedPersonFieldMetadataIds.Favorites, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'favorites', - label: 'Favorites', - targetColumnMap: {}, - description: 'Favorites linked to the contact', - icon: 'IconHeart', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedPersonFieldMetadataIds.Attachments, - objectMetadataId: SeedObjectMetadataIds.Person, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'attachments', - label: 'Attachments', - targetColumnMap: {}, - description: 'Attachments linked to the contact.', - icon: 'IconFileImport', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/pipeline-step.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/pipeline-step.ts deleted file mode 100644 index 2ec3e5fc46..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/pipeline-step.ts +++ /dev/null @@ -1,177 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedPipelineStepFieldMetadataIds { - Id = '20202020-039a-4fbd-b4c1-66dfa9e4bd3f', - CreatedAt = '20202020-816f-4861-9b36-4a2f8ae2791c', - UpdatedAt = '20202020-2d73-4829-b774-522c2f5627d7', - - Name = '20202020-f294-430e-b800-3a411fc05ad3', - Color = '20202020-5b93-4b28-8c45-7988ea68f91b', - Position = '20202020-6296-4cab-aafb-121ef5822b13', - Opportunities = '20202020-22c4-443a-b114-43c97dda5867', -} - -export const seedPipelineStepFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedPipelineStepFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.PipelineStep, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedPipelineStepFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.PipelineStep, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedPipelineStepFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.PipelineStep, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Main Identifier - { - id: SeedPipelineStepFieldMetadataIds.Name, - objectMetadataId: SeedObjectMetadataIds.PipelineStep, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'name', - label: 'Name', - targetColumnMap: { - value: 'name', - }, - description: 'Pipeline Step name', - icon: 'IconCurrencyDollar', - isNullable: false, - isSystem: false, - defaultValue: { value: '' }, - }, - - // Scalar Fields - { - id: SeedPipelineStepFieldMetadataIds.Color, - objectMetadataId: SeedObjectMetadataIds.PipelineStep, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'color', - label: 'Color', - targetColumnMap: { - value: 'color', - }, - description: 'Pipeline Step color', - icon: 'IconColorSwatch', - isNullable: false, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedPipelineStepFieldMetadataIds.Position, - objectMetadataId: SeedObjectMetadataIds.PipelineStep, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.NUMBER, - name: 'position', - label: 'Position', - targetColumnMap: { - value: 'position', - }, - description: 'Pipeline Step position', - icon: 'IconHierarchy2', - isNullable: false, - isSystem: false, - defaultValue: { value: 0 }, - }, - - // Relationships - { - id: SeedPipelineStepFieldMetadataIds.Opportunities, - objectMetadataId: SeedObjectMetadataIds.PipelineStep, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'opportunities', - label: 'Opportunities', - targetColumnMap: {}, - description: 'Opportunities linked to the step.', - icon: 'IconTargetArrow', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-field.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-field.ts deleted file mode 100644 index 58db83d23a..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-field.ts +++ /dev/null @@ -1,209 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedViewFieldFieldMetadataIds { - Id = '20202020-64f2-4ecf-b4c5-45daf154756a', - CreatedAt = '20202020-e137-4e59-b417-a134c050936c', - UpdatedAt = '20202020-17ff-4585-9f3b-cd9ee9523448', - - FieldMetadataId = '20202020-1a5e-4ac1-9530-c7fff8481b79', - IsVisible = '20202020-3aa9-42db-a74d-0fd6b7cb7c4a', - Size = '20202020-b9a1-4c2e-a5af-3a6b4fef4af6', - Position = '20202020-a4bb-440a-add2-81dbd9a74517', - View = '20202020-8788-4508-b771-719807b60e61', - ViewForeignKey = '20202020-c852-4c28-b13a-07788c845d6a', -} - -export const seedViewFieldFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedViewFieldFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.ViewField, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedViewFieldFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.ViewField, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedViewFieldFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.ViewField, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Fields - { - id: SeedViewFieldFieldMetadataIds.FieldMetadataId, - objectMetadataId: SeedObjectMetadataIds.ViewField, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'fieldMetadataId', - label: 'Field Metadata Id', - targetColumnMap: { - value: 'fieldMetadataId', - }, - description: 'View Field target field', - icon: 'IconTag', - isNullable: false, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedViewFieldFieldMetadataIds.View, - objectMetadataId: SeedObjectMetadataIds.ViewField, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'view', - label: 'View Id', - targetColumnMap: {}, - description: 'View Field related view', - icon: 'IconLayoutCollage', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedViewFieldFieldMetadataIds.ViewForeignKey, - objectMetadataId: SeedObjectMetadataIds.ViewField, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'viewId', - label: 'View ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for view', - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedViewFieldFieldMetadataIds.IsVisible, - objectMetadataId: SeedObjectMetadataIds.ViewField, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.BOOLEAN, - name: 'isVisible', - label: 'Visible', - targetColumnMap: { - value: 'isVisible', - }, - description: 'View Field visibility', - icon: 'IconEye', - isNullable: false, - isSystem: false, - defaultValue: { value: true }, - }, - { - id: SeedViewFieldFieldMetadataIds.Size, - objectMetadataId: SeedObjectMetadataIds.ViewField, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.NUMBER, - name: 'size', - label: 'Size', - targetColumnMap: { - value: 'size', - }, - description: 'View Field size', - icon: 'IconEye', - isNullable: false, - isSystem: false, - defaultValue: { value: 0 }, - }, - { - id: SeedViewFieldFieldMetadataIds.Position, - objectMetadataId: SeedObjectMetadataIds.ViewField, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.NUMBER, - name: 'position', - label: 'Position', - targetColumnMap: { - value: 'position', - }, - description: 'View Field position', - icon: 'IconList', - isNullable: false, - isSystem: false, - defaultValue: { value: 0 }, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-filter.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-filter.ts deleted file mode 100644 index 1251755891..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-filter.ts +++ /dev/null @@ -1,209 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedViewFilterFieldMetadataIds { - Id = '20202020-353c-4fb0-9011-1ad8e1dd67f9', - CreatedAt = '20202020-da57-452d-9671-ab3ccac2a9da', - UpdatedAt = '20202020-96c9-4cf1-87b4-8a009c591a16', - - FieldMetadataId = '20202020-78bb-4f2b-a052-260bc8efd694', - View = '20202020-65e5-4082-829d-8c634c20e7b5', - ViewForeignKey = '20202020-c852-4c28-b13a-07788c845d6b', - Operand = '20202020-1d12-465d-ab2c-8af008182730', - Value = '20202020-8b37-46ae-86b8-14287ec06802', - DisplayValue = '20202020-ed89-4892-83fa-d2b2929c6d52', -} - -export const seedViewFilterFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedViewFilterFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.ViewFilter, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedViewFilterFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.ViewFilter, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedViewFilterFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.ViewFilter, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Fields - { - id: SeedViewFilterFieldMetadataIds.FieldMetadataId, - objectMetadataId: SeedObjectMetadataIds.ViewFilter, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'fieldMetadataId', - label: 'Field Metadata Id', - targetColumnMap: { - value: 'fieldMetadataId', - }, - description: 'View Filter target field', - icon: null, - isNullable: false, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedViewFilterFieldMetadataIds.View, - objectMetadataId: SeedObjectMetadataIds.ViewFilter, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'view', - label: 'View', - targetColumnMap: {}, - description: 'View Filter related view', - icon: 'IconLayoutCollage', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedViewFilterFieldMetadataIds.ViewForeignKey, - objectMetadataId: SeedObjectMetadataIds.ViewFilter, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'viewId', - label: 'View ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for view', - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedViewFilterFieldMetadataIds.Operand, - objectMetadataId: SeedObjectMetadataIds.ViewFilter, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'operand', - label: 'Operand', - targetColumnMap: { - value: 'operand', - }, - description: 'View Filter operand', - icon: null, - isNullable: false, - isSystem: false, - defaultValue: { value: 'Contains' }, - }, - { - id: SeedViewFilterFieldMetadataIds.Value, - objectMetadataId: SeedObjectMetadataIds.ViewFilter, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'value', - label: 'Value', - targetColumnMap: { - value: 'value', - }, - description: 'View Filter value', - icon: null, - isNullable: false, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedViewFilterFieldMetadataIds.DisplayValue, - objectMetadataId: SeedObjectMetadataIds.ViewFilter, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'displayValue', - label: 'Display Value', - targetColumnMap: { - value: 'displayValue', - }, - description: 'View Filter Display Value', - icon: null, - isNullable: false, - isSystem: false, - defaultValue: { value: '' }, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-sort.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-sort.ts deleted file mode 100644 index e5fa45b16b..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view-sort.ts +++ /dev/null @@ -1,171 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedViewSortFieldMetadataIds { - Id = '20202020-5870-4665-92a6-a39b7f53352d', - CreatedAt = '20202020-7677-4955-8ffe-06481534d12c', - UpdatedAt = '20202020-16ec-4074-a54b-c8f7f1178cf6', - - FieldMetadataId = '20202020-cb2c-4c8f-a289-c9851b23d064', - View = '20202020-f5d0-467f-a3d8-395ba16b8ebf', - ViewForeignKey = '20202020-c852-4c28-b13a-07788c845d6c', - Direction = '20202020-077e-4451-b1d8-e602c956ebd2', -} - -export const seedViewSortFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedViewSortFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.ViewSort, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedViewSortFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.ViewSort, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedViewSortFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.ViewSort, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Fields - { - id: SeedViewSortFieldMetadataIds.FieldMetadataId, - objectMetadataId: SeedObjectMetadataIds.ViewSort, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'fieldMetadataId', - label: 'Field Metadata Id', - targetColumnMap: { - value: 'fieldMetadataId', - }, - description: 'View Sort target field', - icon: null, - isNullable: false, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedViewSortFieldMetadataIds.View, - objectMetadataId: SeedObjectMetadataIds.ViewSort, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'view', - label: 'View', - targetColumnMap: {}, - description: 'View Sort related view', - icon: 'IconLayoutCollage', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedViewSortFieldMetadataIds.ViewForeignKey, - objectMetadataId: SeedObjectMetadataIds.ViewField, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'viewId', - label: 'View ID (foreign key)', - targetColumnMap: {}, - description: 'Foreign key for view', - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: undefined, - }, - { - id: SeedViewSortFieldMetadataIds.Direction, - objectMetadataId: SeedObjectMetadataIds.ViewSort, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'direction', - label: 'Direction', - targetColumnMap: { - value: 'direction', - }, - description: 'View Sort direction', - icon: null, - isNullable: false, - isSystem: false, - defaultValue: { value: 'asc' }, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view.ts deleted file mode 100644 index 237300d7b7..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/view.ts +++ /dev/null @@ -1,207 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedViewFieldMetadataIds { - Id = '20202020-2957-4431-b3b5-879b5e687c6e', - CreatedAt = '20202020-ad91-42b0-b654-cbd981ddb5bf', - UpdatedAt = '20202020-b4e6-4044-8f6e-886c6eb2a67c', - - Name = '20202020-e10e-4346-8690-b2e582ebc03c', - ObjectMetadataId = '20202020-2c69-46f0-9cf2-1a4f9869d560', - Type = '20202020-2c70-46f0-9cf2-1a4f9869d591', - ViewFields = '20202020-d288-4df4-9548-7b5c5747f623', - ViewSorts = '20202020-3011-4d5c-8133-c01134e733df', - ViewFilters = '20202020-afe8-40bc-9a81-9b33e45131d9', -} - -export const seedViewFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedViewFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.View, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedViewFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.View, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedViewFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.View, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Fields - { - id: SeedViewFieldMetadataIds.Name, - objectMetadataId: SeedObjectMetadataIds.View, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'name', - label: 'Name', - targetColumnMap: { - value: 'name', - }, - description: 'View name', - icon: null, - isNullable: false, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedViewFieldMetadataIds.ObjectMetadataId, - objectMetadataId: SeedObjectMetadataIds.View, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'objectMetadataId', - label: 'Object Metadata Id', - targetColumnMap: { - value: 'objectMetadataId', - }, - description: 'View target object', - icon: null, - isNullable: false, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedViewFieldMetadataIds.Type, - objectMetadataId: SeedObjectMetadataIds.View, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'type', - label: 'Type', - targetColumnMap: { - value: 'type', - }, - description: 'View type', - icon: null, - isNullable: false, - isSystem: false, - defaultValue: { value: 'table' }, - }, - { - id: SeedViewFieldMetadataIds.ViewFields, - objectMetadataId: SeedObjectMetadataIds.View, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'viewFields', - label: 'View Fields', - targetColumnMap: {}, - description: 'View Fields', - icon: 'IconTag', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedViewFieldMetadataIds.ViewSorts, - objectMetadataId: SeedObjectMetadataIds.View, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'viewSorts', - label: 'View Sorts', - targetColumnMap: {}, - description: 'View Sorts', - icon: 'IconArrowsSort', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedViewFieldMetadataIds.ViewFilters, - objectMetadataId: SeedObjectMetadataIds.View, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'viewFilters', - label: 'View Filters', - targetColumnMap: {}, - description: 'View Filters', - icon: 'IconFilterBolt', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/webhook.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/webhook.ts deleted file mode 100644 index 96705e95b7..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/webhook.ts +++ /dev/null @@ -1,137 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedWebhookFieldMetadataIds { - Id = '20202020-bc24-4387-8abe-9fbe7849f820', - CreatedAt = '20202020-c643-4324-9032-f38117fbca3b', - UpdatedAt = '20202020-489b-4f1d-80a4-2dddf6fa0e7c', - - TargetUrl = '20202020-c16e-4ba8-bb24-bbd88e9cdabc', - Operation = '20202020-5995-493a-92a8-31376e5c052a', -} - -export const seedWebhookFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedWebhookFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.Webhook, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedWebhookFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.Webhook, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedWebhookFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.Webhook, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Scalar fields - { - id: SeedWebhookFieldMetadataIds.TargetUrl, - objectMetadataId: SeedObjectMetadataIds.Webhook, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'targetUrl', - label: 'Target Url', - targetColumnMap: { - value: 'targetUrl', - }, - description: 'Webhook target url', - icon: 'IconLink', - isNullable: false, - isSystem: false, - defaultValue: { value: '' }, - }, - { - id: SeedWebhookFieldMetadataIds.Operation, - objectMetadataId: SeedObjectMetadataIds.Webhook, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'operation', - label: 'Operation', - targetColumnMap: { - value: 'operation', - }, - description: 'Webhook operation', - icon: 'IconCheckbox', - isNullable: false, - isSystem: false, - defaultValue: { value: '' }, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/workspace-member.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/workspace-member.ts deleted file mode 100644 index 19d68c3fb3..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/field-metadata/workspace-member.ts +++ /dev/null @@ -1,300 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const fieldMetadataTableName = 'fieldMetadata'; - -export enum SeedWorkspaceMemberFieldMetadataIds { - Id = '20202020-678e-4702-a535-2549ef07f1ca', - CreatedAt = '20202020-1cbf-4b32-8c33-fbfedcd9afa8', - UpdatedAt = '20202020-1ba3-4c24-b2cd-b0789633e8d4', - - Name = '20202020-8c37-4163-ba06-1dada334ce3e', - AvatarUrl = '20202020-7ba6-40d5-934b-17146183a212', - Locale = '20202020-10f6-4df9-8d6f-a760b65bd800', - ColorScheme = '20202020-83f2-4c5f-96b0-0c51ecc160e3', - UserId = '20202020-f2c1-4ca1-9ca5-7b9d5cc87eb0', - AuthoredActivities = '20202020-37a0-4db4-9c9f-fd3e3f4e47fc', - AssignedActivities = '20202020-ac05-44b9-9526-764dd5ce14e2', - AuthoredAttachments = '20202020-7e0c-4dc4-be49-37de4396349e', - Favorites = '20202020-5ecb-405b-8712-171bb8916b96', - Settings = '20202020-50ed-46ed-8198-65e237b83eb9', - AccountOwnerForCompanies = '20202020-41bb-4c17-8979-40fa915df9e1', - AuthoredComments = '20202020-7238-4e2a-9ccf-d2c8f604933a', -} - -export const seedWorkspaceMemberFieldMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${fieldMetadataTableName}`, [ - 'id', - 'objectMetadataId', - 'isCustom', - 'workspaceId', - 'isActive', - 'type', - 'name', - 'label', - 'targetColumnMap', - 'description', - 'icon', - 'isNullable', - 'isSystem', - 'defaultValue', - ]) - .orIgnore() - .values([ - // Default fields - { - id: SeedWorkspaceMemberFieldMetadataIds.Id, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'id', - label: 'Id', - targetColumnMap: { - value: 'id', - }, - description: undefined, - icon: undefined, - isNullable: false, - isSystem: true, - defaultValue: { type: 'uuid' }, - }, - { - id: SeedWorkspaceMemberFieldMetadataIds.CreatedAt, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'createdAt', - label: 'Creation date', - targetColumnMap: { - value: 'createdAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - { - id: SeedWorkspaceMemberFieldMetadataIds.UpdatedAt, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.DATE_TIME, - name: 'updatedAt', - label: 'Update date', - targetColumnMap: { - value: 'updatedAt', - }, - description: undefined, - icon: 'IconCalendar', - isNullable: false, - isSystem: true, - defaultValue: { type: 'now' }, - }, - // Scalar fields - { - id: SeedWorkspaceMemberFieldMetadataIds.Name, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.FULL_NAME, - name: 'name', - label: 'Name', - targetColumnMap: { - firstName: 'nameFirstName', - lastName: 'nameLastName', - }, - description: 'Workspace member name', - icon: 'IconCircleUser', - isNullable: false, - isSystem: false, - defaultValue: { firstName: '', lastName: '' }, - }, - { - id: SeedWorkspaceMemberFieldMetadataIds.AvatarUrl, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: 'TEXT', - name: 'avatarUrl', - label: 'Avatar Url', - targetColumnMap: { - value: 'avatarUrl', - }, - description: 'Workspace member avatar', - icon: 'IconFileUpload', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedWorkspaceMemberFieldMetadataIds.UserId, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.UUID, - name: 'userId', - label: 'User Id', - targetColumnMap: { - value: 'userId', - }, - description: 'Associated User Id', - icon: 'IconCircleUsers', - isNullable: false, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedWorkspaceMemberFieldMetadataIds.ColorScheme, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'colorScheme', - label: 'Color Scheme', - targetColumnMap: { - value: 'colorScheme', - }, - description: 'Preferred color scheme', - icon: 'IconColorSwatch', - isNullable: true, - isSystem: false, - defaultValue: { value: 'Light' }, - }, - { - id: SeedWorkspaceMemberFieldMetadataIds.Locale, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.TEXT, - name: 'locale', - label: 'Language', - targetColumnMap: { - value: 'locale', - }, - description: 'Preferred language', - icon: 'IconLanguage', - isNullable: false, - isSystem: false, - defaultValue: { value: 'en' }, - }, - - // Relationships - { - id: SeedWorkspaceMemberFieldMetadataIds.AuthoredActivities, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'authoredActivities', - label: 'Authored activities', - targetColumnMap: {}, - description: 'Activities created by the workspace member', - icon: 'IconCheckbox', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedWorkspaceMemberFieldMetadataIds.AssignedActivities, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'assignedActivities', - label: 'Assigned activities', - targetColumnMap: {}, - description: 'Activities assigned to the workspace member', - icon: 'IconCheckbox', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedWorkspaceMemberFieldMetadataIds.Favorites, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'favorites', - label: 'Favorites', - targetColumnMap: {}, - description: 'Favorites linked to the workspace member', - icon: 'IconHeart', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedWorkspaceMemberFieldMetadataIds.AccountOwnerForCompanies, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'accountOwnerForCompanies', - label: 'Account Owner For Companies', - targetColumnMap: {}, - description: 'Account owner for companies', - icon: 'IconBriefcase', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedWorkspaceMemberFieldMetadataIds.AuthoredAttachments, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'authoredAttachments', - label: 'Authored attachments', - targetColumnMap: {}, - description: 'Attachments created by the workspace member', - icon: 'IconFileImport', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - { - id: SeedWorkspaceMemberFieldMetadataIds.AuthoredComments, - objectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - isCustom: false, - workspaceId: SeedWorkspaceId, - isActive: true, - type: FieldMetadataType.RELATION, - name: 'authoredComments', - label: 'Authored comments', - targetColumnMap: {}, - description: 'Authored comments', - icon: 'IconComment', - isNullable: true, - isSystem: false, - defaultValue: undefined, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/index.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/index.ts deleted file mode 100644 index 5d47f02d73..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/index.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { seedCompanyFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/company'; -import { seedViewFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/view'; -import { seedViewFieldFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/view-field'; -import { seedViewFilterFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/view-filter'; -import { seedViewSortFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/view-sort'; -import { seedObjectMetadata } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { seedViewRelationMetadata } from 'src/database/typeorm-seeds/metadata/relation-metadata/view'; -import { seedActivityTargetFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/activity-target'; -import { seedActivityFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/activity'; -import { seedApiKeyFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/api-key'; -import { seedAttachmentFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/attachment'; -import { seedCommentFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/comment'; -import { seedFavoriteFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/favorite'; -import { seedOpportunityFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/opportunity'; -import { seedPersonFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/person'; -import { seedPipelineStepFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/pipeline-step'; -import { seedWorkspaceMemberFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/workspace-member'; -import { seedCompanyRelationMetadata } from 'src/database/typeorm-seeds/metadata/relation-metadata/company'; -import { seedActivityRelationMetadata } from 'src/database/typeorm-seeds/metadata/relation-metadata/activity'; -import { seedPipelineStepRelationMetadata } from 'src/database/typeorm-seeds/metadata/relation-metadata/pipeline-step'; -import { seedPersonRelationMetadata } from 'src/database/typeorm-seeds/metadata/relation-metadata/person'; -import { seedWorkspaceMemberRelationMetadata } from 'src/database/typeorm-seeds/metadata/relation-metadata/workspace-member'; -import { seedDataSource } from 'src/database/typeorm-seeds/metadata/data-source'; -import { seedWebhookFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata/webhook'; - -export const seedMetadataSchema = async (workspaceDataSource: DataSource) => { - const schemaName = 'metadata'; - - await seedDataSource(workspaceDataSource, schemaName); - await seedObjectMetadata(workspaceDataSource, schemaName); - - await seedActivityTargetFieldMetadata(workspaceDataSource, schemaName); - await seedActivityFieldMetadata(workspaceDataSource, schemaName); - await seedApiKeyFieldMetadata(workspaceDataSource, schemaName); - await seedAttachmentFieldMetadata(workspaceDataSource, schemaName); - await seedWebhookFieldMetadata(workspaceDataSource, schemaName); - await seedCommentFieldMetadata(workspaceDataSource, schemaName); - await seedCompanyFieldMetadata(workspaceDataSource, schemaName); - await seedFavoriteFieldMetadata(workspaceDataSource, schemaName); - await seedOpportunityFieldMetadata(workspaceDataSource, schemaName); - await seedPersonFieldMetadata(workspaceDataSource, schemaName); - await seedPipelineStepFieldMetadata(workspaceDataSource, schemaName); - await seedViewFieldMetadata(workspaceDataSource, schemaName); - await seedViewFieldFieldMetadata(workspaceDataSource, schemaName); - await seedViewFilterFieldMetadata(workspaceDataSource, schemaName); - await seedViewSortFieldMetadata(workspaceDataSource, schemaName); - await seedViewRelationMetadata(workspaceDataSource, schemaName); - await seedWorkspaceMemberFieldMetadata(workspaceDataSource, schemaName); - - await seedActivityRelationMetadata(workspaceDataSource, schemaName); - await seedCompanyRelationMetadata(workspaceDataSource, schemaName); - await seedPersonRelationMetadata(workspaceDataSource, schemaName); - await seedPipelineStepRelationMetadata(workspaceDataSource, schemaName); - await seedViewRelationMetadata(workspaceDataSource, schemaName); - await seedWorkspaceMemberRelationMetadata(workspaceDataSource, schemaName); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/object-metadata.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/object-metadata.ts deleted file mode 100644 index a8c33b3313..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/object-metadata.ts +++ /dev/null @@ -1,306 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; -import { SeedDataSourceId } from 'src/database/typeorm-seeds/metadata/data-source'; -import { SeedCompanyFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/company'; -import { SeedPersonFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/person'; - -const tableName = 'objectMetadata'; - -export enum SeedObjectMetadataIds { - Company = '20202020-480c-434e-b4c7-e22408b97047', - Person = '20202020-c64b-44bc-bd2c-502c99f49dca', - Opportunity = '20202020-cae9-4ff4-9579-f7d9fe44c937', - PipelineStep = '20202020-1029-4661-9e91-83bad932bdcd', - WorkspaceMember = '20202020-b550-40bb-a96b-9ab54b664753', - Webhook = '20202020-ddee-40de-9c9b-5f82a3503360', - ApiKey = '20202020-d8d0-4c2d-a370-5499b2181d02', - Activity = '20202020-8ee3-4f67-84ab-1b7a6eb5a448', - ActivityTarget = '20202020-439a-4a41-83a3-3cda03d01d38', - Comment = '20202020-4de3-4e65-ac60-b40b8e08d7d6', - Attachment = '20202020-5f98-4317-915d-3779bb821be2', - Favorite = '20202020-90e4-4701-a350-8ab75e23e3b8', - View = '20202020-767f-473f-8fd0-6cdbefbf8dbe', - ViewField = '20202020-485c-4c48-a22e-0d9a164f9647', - ViewFilter = '20202020-4461-4e2d-bf9e-9b47e68846d3', - ViewSort = '20202020-cf28-41dd-b98b-d6e1f5b3a251', -} - -export const seedObjectMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${tableName}`, [ - 'id', - 'nameSingular', - 'namePlural', - 'labelSingular', - 'labelPlural', - 'targetTableName', - 'description', - 'icon', - 'dataSourceId', - 'workspaceId', - 'isActive', - 'isSystem', - 'labelIdentifierFieldMetadataId', - 'imageIdentifierFieldMetadataId', - ]) - .orIgnore() - .values([ - { - id: SeedObjectMetadataIds.Company, - nameSingular: 'company', - namePlural: 'companies', - labelSingular: 'Company', - labelPlural: 'Companies', - targetTableName: 'company', - description: 'A company', - icon: 'IconBuildingSkyscraper', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: false, - labelIdentifierFieldMetadataId: SeedCompanyFieldMetadataIds.Name, - imageIdentifierFieldMetadataId: SeedCompanyFieldMetadataIds.DomainName, - }, - { - id: SeedObjectMetadataIds.Person, - nameSingular: 'person', - namePlural: 'people', - labelSingular: 'Person', - labelPlural: 'People', - targetTableName: 'person', - description: 'A person', - icon: 'IconUser', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: false, - labelIdentifierFieldMetadataId: SeedPersonFieldMetadataIds.Email, - imageIdentifierFieldMetadataId: SeedPersonFieldMetadataIds.AvatarUrl, - }, - ]) - .execute(); - - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${tableName}`, [ - 'id', - 'nameSingular', - 'namePlural', - 'labelSingular', - 'labelPlural', - 'targetTableName', - 'description', - 'icon', - 'dataSourceId', - 'workspaceId', - 'isActive', - 'isSystem', - ]) - .orIgnore() - .values([ - { - id: SeedObjectMetadataIds.Opportunity, - nameSingular: 'opportunity', - namePlural: 'opportunities', - labelSingular: 'Opportunity', - labelPlural: 'Opportunities', - targetTableName: 'opportunity', - description: 'An opportunity', - icon: 'IconTargetArrow', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: false, - }, - { - id: SeedObjectMetadataIds.PipelineStep, - nameSingular: 'pipelineStep', - namePlural: 'pipelineSteps', - labelSingular: 'Pipeline Step', - labelPlural: 'Pipeline Steps', - targetTableName: 'pipelineStep', - description: 'A pipeline step', - icon: 'IconLayoutKanban', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.WorkspaceMember, - nameSingular: 'workspaceMember', - namePlural: 'workspaceMembers', - labelSingular: 'Workspace Member', - labelPlural: 'Workspace Members', - targetTableName: 'workspaceMember', - description: 'A workspace member', - icon: 'IconUserCircle', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.Webhook, - nameSingular: 'webhook', - namePlural: 'webhooks', - labelSingular: 'Webhook', - labelPlural: 'Webhooks', - targetTableName: 'webhook', - description: 'A webhook', - icon: 'IconRobot', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.ApiKey, - nameSingular: 'apiKey', - namePlural: 'apiKeys', - labelSingular: 'Api Key', - labelPlural: 'Api Keys', - targetTableName: 'apiKey', - description: 'An api key', - icon: 'IconRobot', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.Activity, - nameSingular: 'activity', - namePlural: 'activities', - labelSingular: 'Activity', - labelPlural: 'Activities', - targetTableName: 'activity', - description: 'An activity', - icon: 'IconCheckbox', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.ActivityTarget, - nameSingular: 'activityTarget', - namePlural: 'activityTargets', - labelSingular: 'Activity Target', - labelPlural: 'Activity Targets', - targetTableName: 'activityTarget', - description: 'An activity target', - icon: 'IconCheckbox', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.Comment, - nameSingular: 'comment', - namePlural: 'comments', - labelSingular: 'Comment', - labelPlural: 'Comments', - targetTableName: 'comment', - description: 'A comment', - icon: 'IconMessageCircle', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.Attachment, - nameSingular: 'attachment', - namePlural: 'attachments', - labelSingular: 'Attachment', - labelPlural: 'Attachments', - targetTableName: 'attachment', - description: 'An attachment', - icon: 'IconFileImport', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.Favorite, - nameSingular: 'favorite', - namePlural: 'favorites', - labelSingular: 'Favorite', - labelPlural: 'Favorites', - targetTableName: 'favorite', - description: 'A favorite', - icon: 'IconHeart', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.View, - nameSingular: 'view', - namePlural: 'views', - labelSingular: 'View', - labelPlural: 'Views', - targetTableName: 'view', - description: '(System) Views', - icon: 'IconLayoutCollage', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.ViewField, - nameSingular: 'viewField', - namePlural: 'viewFields', - labelSingular: 'View Field', - labelPlural: 'View Fields', - targetTableName: 'viewField', - description: '(System) View Fields', - icon: 'IconTag', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.ViewFilter, - nameSingular: 'viewFilter', - namePlural: 'viewFilters', - labelSingular: 'View Filter', - labelPlural: 'View Filters', - targetTableName: 'viewFilter', - description: '(System) View Filters', - icon: 'IconFilterBolt', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - { - id: SeedObjectMetadataIds.ViewSort, - nameSingular: 'viewSort', - namePlural: 'viewSorts', - labelSingular: 'View Sort', - labelPlural: 'View Sorts', - targetTableName: 'viewSort', - description: '(System) View Sorts', - icon: 'IconArrowsSort', - dataSourceId: SeedDataSourceId, - workspaceId: SeedWorkspaceId, - isActive: true, - isSystem: true, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/activity.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/activity.ts deleted file mode 100644 index c507e0e97c..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/activity.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { SeedActivityFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/activity'; -import { SeedActivityTargetFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/activity-target'; -import { SeedAttachmentFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/attachment'; -import { SeedCommentFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/comment'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const tableName = 'relationMetadata'; - -export const seedActivityRelationMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${tableName}`, [ - 'relationType', - 'fromObjectMetadataId', - 'toObjectMetadataId', - 'fromFieldMetadataId', - 'toFieldMetadataId', - 'workspaceId', - ]) - .orIgnore() - .values([ - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Activity, - toObjectMetadataId: SeedObjectMetadataIds.ActivityTarget, - fromFieldMetadataId: SeedActivityFieldMetadataIds.ActivityTargets, - toFieldMetadataId: SeedActivityTargetFieldMetadataIds.Activity, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Activity, - toObjectMetadataId: SeedObjectMetadataIds.Attachment, - fromFieldMetadataId: SeedActivityFieldMetadataIds.Attachments, - toFieldMetadataId: SeedAttachmentFieldMetadataIds.Activity, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Activity, - toObjectMetadataId: SeedObjectMetadataIds.Comment, - fromFieldMetadataId: SeedActivityFieldMetadataIds.Comments, - toFieldMetadataId: SeedCommentFieldMetadataIds.Activity, - workspaceId: SeedWorkspaceId, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/company.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/company.ts deleted file mode 100644 index 78a660d558..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/company.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { SeedCompanyFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/company'; -import { SeedPersonFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/person'; -import { SeedFavoriteFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/favorite'; -import { SeedAttachmentFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/attachment'; -import { SeedOpportunityFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/opportunity'; -import { SeedActivityTargetFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/activity-target'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const tableName = 'relationMetadata'; - -export const seedCompanyRelationMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${tableName}`, [ - 'relationType', - 'fromObjectMetadataId', - 'toObjectMetadataId', - 'fromFieldMetadataId', - 'toFieldMetadataId', - 'workspaceId', - ]) - .orIgnore() - .values([ - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Company, - toObjectMetadataId: SeedObjectMetadataIds.Person, - fromFieldMetadataId: SeedCompanyFieldMetadataIds.People, - toFieldMetadataId: SeedPersonFieldMetadataIds.Company, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Company, - toObjectMetadataId: SeedObjectMetadataIds.Favorite, - fromFieldMetadataId: SeedCompanyFieldMetadataIds.Favorites, - toFieldMetadataId: SeedFavoriteFieldMetadataIds.Company, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Company, - toObjectMetadataId: SeedObjectMetadataIds.Attachment, - fromFieldMetadataId: SeedCompanyFieldMetadataIds.Attachments, - toFieldMetadataId: SeedAttachmentFieldMetadataIds.Company, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Company, - toObjectMetadataId: SeedObjectMetadataIds.Opportunity, - fromFieldMetadataId: SeedCompanyFieldMetadataIds.Opportunities, - toFieldMetadataId: SeedOpportunityFieldMetadataIds.Company, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Company, - toObjectMetadataId: SeedObjectMetadataIds.ActivityTarget, - fromFieldMetadataId: SeedCompanyFieldMetadataIds.ActivityTargets, - toFieldMetadataId: SeedActivityTargetFieldMetadataIds.Company, - workspaceId: SeedWorkspaceId, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/person.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/person.ts deleted file mode 100644 index cb51e0b45f..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/person.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { SeedFavoriteFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/favorite'; -import { SeedPersonFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/person'; -import { SeedActivityTargetFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/activity-target'; -import { SeedAttachmentFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/attachment'; -import { SeedOpportunityFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/opportunity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const tableName = 'relationMetadata'; - -export const seedPersonRelationMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${tableName}`, [ - 'relationType', - 'fromObjectMetadataId', - 'toObjectMetadataId', - 'fromFieldMetadataId', - 'toFieldMetadataId', - 'workspaceId', - ]) - .orIgnore() - .values([ - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Person, - toObjectMetadataId: SeedObjectMetadataIds.Favorite, - fromFieldMetadataId: SeedPersonFieldMetadataIds.Favorites, - toFieldMetadataId: SeedFavoriteFieldMetadataIds.Person, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Person, - toObjectMetadataId: SeedObjectMetadataIds.Attachment, - fromFieldMetadataId: SeedPersonFieldMetadataIds.Attachments, - toFieldMetadataId: SeedAttachmentFieldMetadataIds.Person, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Person, - toObjectMetadataId: SeedObjectMetadataIds.Opportunity, - fromFieldMetadataId: SeedPersonFieldMetadataIds.Opportunities, - toFieldMetadataId: SeedOpportunityFieldMetadataIds.Person, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Person, - toObjectMetadataId: SeedObjectMetadataIds.Opportunity, - fromFieldMetadataId: SeedPersonFieldMetadataIds.ContactForOpportunities, - toFieldMetadataId: SeedOpportunityFieldMetadataIds.PointOfContact, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.Person, - toObjectMetadataId: SeedObjectMetadataIds.ActivityTarget, - fromFieldMetadataId: SeedPersonFieldMetadataIds.ActivityTargets, - toFieldMetadataId: SeedActivityTargetFieldMetadataIds.Person, - workspaceId: SeedWorkspaceId, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/pipeline-step.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/pipeline-step.ts deleted file mode 100644 index baa4c449b4..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/pipeline-step.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { SeedPipelineStepFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/pipeline-step'; -import { SeedOpportunityFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/opportunity'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const tableName = 'relationMetadata'; - -export const seedPipelineStepRelationMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${tableName}`, [ - 'relationType', - 'fromObjectMetadataId', - 'toObjectMetadataId', - 'fromFieldMetadataId', - 'toFieldMetadataId', - 'workspaceId', - ]) - .orIgnore() - .values([ - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.PipelineStep, - toObjectMetadataId: SeedObjectMetadataIds.Opportunity, - fromFieldMetadataId: SeedPipelineStepFieldMetadataIds.Opportunities, - toFieldMetadataId: SeedOpportunityFieldMetadataIds.PipelineStep, - workspaceId: SeedWorkspaceId, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/view.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/view.ts deleted file mode 100644 index 2a2c0d07f6..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/view.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { SeedViewFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/view'; -import { SeedViewFieldFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/view-field'; -import { SeedViewFilterFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/view-filter'; -import { SeedViewSortFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/view-sort'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const tableName = 'relationMetadata'; - -export const seedViewRelationMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${tableName}`, [ - 'relationType', - 'fromObjectMetadataId', - 'toObjectMetadataId', - 'fromFieldMetadataId', - 'toFieldMetadataId', - 'workspaceId', - ]) - .orIgnore() - .values([ - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.View, - toObjectMetadataId: SeedObjectMetadataIds.ViewField, - fromFieldMetadataId: SeedViewFieldMetadataIds.ViewFields, - toFieldMetadataId: SeedViewFieldFieldMetadataIds.View, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.View, - toObjectMetadataId: SeedObjectMetadataIds.ViewFilter, - fromFieldMetadataId: SeedViewFieldMetadataIds.ViewFilters, - toFieldMetadataId: SeedViewFilterFieldMetadataIds.View, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.View, - toObjectMetadataId: SeedObjectMetadataIds.ViewSort, - fromFieldMetadataId: SeedViewFieldMetadataIds.ViewSorts, - toFieldMetadataId: SeedViewSortFieldMetadataIds.View, - workspaceId: SeedWorkspaceId, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/workspace-member.ts b/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/workspace-member.ts deleted file mode 100644 index 404df06b32..0000000000 --- a/packages/twenty-server/src/database/typeorm-seeds/metadata/relation-metadata/workspace-member.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { DataSource } from 'typeorm'; - -import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { SeedObjectMetadataIds } from 'src/database/typeorm-seeds/metadata/object-metadata'; -import { SeedCompanyFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/company'; -import { SeedWorkspaceMemberFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/workspace-member'; -import { SeedFavoriteFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/favorite'; -import { SeedActivityFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/activity'; -import { SeedCommentFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/comment'; -import { SeedAttachmentFieldMetadataIds } from 'src/database/typeorm-seeds/metadata/field-metadata/attachment'; -import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces'; - -const tableName = 'relationMetadata'; - -export const seedWorkspaceMemberRelationMetadata = async ( - workspaceDataSource: DataSource, - schemaName: string, -) => { - await workspaceDataSource - .createQueryBuilder() - .insert() - .into(`${schemaName}.${tableName}`, [ - 'relationType', - 'fromObjectMetadataId', - 'toObjectMetadataId', - 'fromFieldMetadataId', - 'toFieldMetadataId', - 'workspaceId', - ]) - .orIgnore() - .values([ - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - toObjectMetadataId: SeedObjectMetadataIds.Company, - fromFieldMetadataId: - SeedWorkspaceMemberFieldMetadataIds.AccountOwnerForCompanies, - toFieldMetadataId: SeedCompanyFieldMetadataIds.AccountOwner, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - toObjectMetadataId: SeedObjectMetadataIds.Favorite, - fromFieldMetadataId: SeedWorkspaceMemberFieldMetadataIds.Favorites, - toFieldMetadataId: SeedFavoriteFieldMetadataIds.WorkspaceMember, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - toObjectMetadataId: SeedObjectMetadataIds.Activity, - fromFieldMetadataId: - SeedWorkspaceMemberFieldMetadataIds.AuthoredActivities, - toFieldMetadataId: SeedActivityFieldMetadataIds.Author, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - toObjectMetadataId: SeedObjectMetadataIds.Activity, - fromFieldMetadataId: - SeedWorkspaceMemberFieldMetadataIds.AssignedActivities, - toFieldMetadataId: SeedActivityFieldMetadataIds.Assignee, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - toObjectMetadataId: SeedObjectMetadataIds.Comment, - fromFieldMetadataId: - SeedWorkspaceMemberFieldMetadataIds.AuthoredComments, - toFieldMetadataId: SeedCommentFieldMetadataIds.Author, - workspaceId: SeedWorkspaceId, - }, - { - relationType: RelationMetadataType.ONE_TO_MANY, - fromObjectMetadataId: SeedObjectMetadataIds.WorkspaceMember, - toObjectMetadataId: SeedObjectMetadataIds.Attachment, - fromFieldMetadataId: - SeedWorkspaceMemberFieldMetadataIds.AuthoredAttachments, - toFieldMetadataId: SeedAttachmentFieldMetadataIds.Author, - workspaceId: SeedWorkspaceId, - }, - ]) - .execute(); -}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/workspace/workspaceMember.ts b/packages/twenty-server/src/database/typeorm-seeds/workspace/workspaceMember.ts index b093e4d1bc..2f0054e87a 100644 --- a/packages/twenty-server/src/database/typeorm-seeds/workspace/workspaceMember.ts +++ b/packages/twenty-server/src/database/typeorm-seeds/workspace/workspaceMember.ts @@ -23,6 +23,7 @@ export const seedWorkspaceMember = async ( 'nameLastName', 'locale', 'colorScheme', + 'userEmail', 'userId', ]) .orIgnore() @@ -33,6 +34,7 @@ export const seedWorkspaceMember = async ( nameLastName: 'Apple', locale: 'en', colorScheme: 'Light', + userEmail: 'tim@apple.dev', userId: SeedUserIds.Tim, }, { @@ -41,6 +43,7 @@ export const seedWorkspaceMember = async ( nameLastName: 'Ive', locale: 'en', colorScheme: 'Light', + userEmail: 'jony.ive@apple.dev', userId: SeedUserIds.Jony, }, { @@ -49,6 +52,7 @@ export const seedWorkspaceMember = async ( nameLastName: 'Shiler', locale: 'en', colorScheme: 'Light', + userEmail: 'phil.schiler@apple.dev', userId: SeedUserIds.Phil, }, ]) diff --git a/packages/twenty-server/src/metadata/data-source/data-source.entity.ts b/packages/twenty-server/src/metadata/data-source/data-source.entity.ts index 0b5c07c5ac..55b10cd5f8 100644 --- a/packages/twenty-server/src/metadata/data-source/data-source.entity.ts +++ b/packages/twenty-server/src/metadata/data-source/data-source.entity.ts @@ -10,13 +10,16 @@ import { import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity'; -type DataSourceType = DataSourceOptions['type']; +export type DataSourceType = DataSourceOptions['type']; @Entity('dataSource') export class DataSourceEntity { @PrimaryGeneratedColumn('uuid') id: string; + @Column({ nullable: true }) + label: string; + @Column({ nullable: true }) url: string; @@ -26,9 +29,6 @@ export class DataSourceEntity { @Column({ type: 'enum', enum: ['postgres'], default: 'postgres' }) type: DataSourceType; - @Column({ nullable: true, name: 'label' }) - label: string; - @Column({ default: false }) isRemote: boolean; diff --git a/packages/twenty-server/src/metadata/field-metadata/field-metadata.service.ts b/packages/twenty-server/src/metadata/field-metadata/field-metadata.service.ts index 49f0fca457..e3cb818516 100644 --- a/packages/twenty-server/src/metadata/field-metadata/field-metadata.service.ts +++ b/packages/twenty-server/src/metadata/field-metadata/field-metadata.service.ts @@ -94,6 +94,7 @@ export class FieldMetadataService extends TypeOrmQueryService, ): Promise { return this.objectMetadataRepository.findOne({ - ...options, - where: { - ...options.where, - workspaceId, - }, relations: [ 'fields', 'fields.fromRelationMetadata', 'fields.toRelationMetadata', ], + ...options, + where: { + ...options.where, + workspaceId, + }, }); } @@ -331,17 +335,17 @@ export class ObjectMetadataService extends TypeOrmQueryService, ) { return this.objectMetadataRepository.find({ - ...options, - where: { - ...options?.where, - workspaceId, - }, relations: [ 'fields', 'fields.fromRelationMetadata', 'fields.toRelationMetadata', 'fields.fromRelationMetadata.toObjectMetadata', ], + ...options, + where: { + ...options?.where, + workspaceId, + }, }); } diff --git a/packages/twenty-server/src/metadata/relation-metadata/relation-metadata.service.ts b/packages/twenty-server/src/metadata/relation-metadata/relation-metadata.service.ts index 0c42a8d9c9..dff41eb178 100644 --- a/packages/twenty-server/src/metadata/relation-metadata/relation-metadata.service.ts +++ b/packages/twenty-server/src/metadata/relation-metadata/relation-metadata.service.ts @@ -200,6 +200,9 @@ export class RelationMetadataService extends TypeOrmQueryService, ) {} - /** - * Insert all standard migrations that have not been inserted yet - * - * @param workspaceId - */ - public async insertStandardMigrations(workspaceId: string): Promise { - // TODO: we actually don't need to fetch all of them, to improve later so it scales well. - const insertedStandardMigrations = - await this.workspaceMigrationRepository.find({ - where: { workspaceId, isCustom: false }, - }); - - const insertedStandardMigrationsMapByName = - insertedStandardMigrations.reduce((acc, migration) => { - acc[migration.name] = migration; - - return acc; - }, {}); - - const standardMigrationsListThatNeedToBeInserted = Object.entries( - standardMigrations, - ) - .filter(([name]) => !insertedStandardMigrationsMapByName[name]) - .map(([name, migrations]) => ({ name, migrations })); - - const standardMigrationsThatNeedToBeInserted = - standardMigrationsListThatNeedToBeInserted.map((migration) => ({ - ...migration, - workspaceId, - isCustom: false, - })); - - await this.workspaceMigrationRepository.save( - standardMigrationsThatNeedToBeInserted, - ); - } - /** * Get all pending migrations for a given workspaceId * diff --git a/packages/twenty-server/src/utils/typed-reflect.ts b/packages/twenty-server/src/utils/typed-reflect.ts new file mode 100644 index 0000000000..610644769c --- /dev/null +++ b/packages/twenty-server/src/utils/typed-reflect.ts @@ -0,0 +1,71 @@ +import 'reflect-metadata'; + +import { GateDecoratorParams } from 'src/workspace/workspace-sync-metadata/interfaces/gate-decorator.interface'; +import { ReflectFieldMetadata } from 'src/workspace/workspace-sync-metadata/interfaces/reflect-field-metadata.interface'; +import { ReflectObjectMetadata } from 'src/workspace/workspace-sync-metadata/interfaces/reflect-object-metadata.interface'; +import { ReflectRelationMetadata } from 'src/workspace/workspace-sync-metadata/interfaces/reflect-relation-metadata.interface'; + +export interface ReflectMetadataTypeMap { + objectMetadata: ReflectObjectMetadata; + fieldMetadata: ReflectFieldMetadata; + relationMetadata: ReflectRelationMetadata[]; + gate: GateDecoratorParams; + isNullable: true; + isSystem: true; +} + +export class TypedReflect { + static defineMetadata( + metadataKey: T, + metadataValue: ReflectMetadataTypeMap[T], + target: object, + ): void; + + static defineMetadata( + metadataKey: T, + metadataValue: ReflectMetadataTypeMap[T], + target: object, + propertyKey: string, + ): void; + + static defineMetadata( + metadataKey: T, + metadataValue: ReflectMetadataTypeMap[T], + target: object, + propertyKeyOrUndefined?: string, + ) { + if (propertyKeyOrUndefined === undefined) { + Reflect.defineMetadata(metadataKey, metadataValue, target); + } else { + Reflect.defineMetadata( + metadataKey, + metadataValue, + target, + propertyKeyOrUndefined, + ); + } + } + + static getMetadata( + metadataKey: T, + target: object, + ): ReflectMetadataTypeMap[T] | undefined; + + static getMetadata( + metadataKey: T, + target: object, + propertyKey: string, + ): ReflectMetadataTypeMap[T] | undefined; + + static getMetadata( + metadataKey: T, + target: object, + propertyKeyOrUndefined?: string, + ) { + if (propertyKeyOrUndefined === undefined) { + return Reflect.getMetadata(metadataKey, target); + } else { + return Reflect.getMetadata(metadataKey, target, propertyKeyOrUndefined); + } + } +} diff --git a/packages/twenty-server/src/workspace/workspace-migration-runner/commands/run-workspace-migrations.command.ts b/packages/twenty-server/src/workspace/workspace-migration-runner/commands/run-workspace-migrations.command.ts deleted file mode 100644 index 8962c0c618..0000000000 --- a/packages/twenty-server/src/workspace/workspace-migration-runner/commands/run-workspace-migrations.command.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Command, CommandRunner, Option } from 'nest-commander'; - -import { WorkspaceMigrationService } from 'src/metadata/workspace-migration/workspace-migration.service'; -import { WorkspaceMigrationRunnerService } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.service'; - -// TODO: implement dry-run -interface RunWorkspaceMigrationsOptions { - workspaceId: string; -} - -@Command({ - name: 'workspace:migrate', - description: 'Run workspace migrations', -}) -export class RunWorkspaceMigrationsCommand extends CommandRunner { - constructor( - private readonly workspaceMigrationService: WorkspaceMigrationService, - private readonly workspaceMigrationRunnerService: WorkspaceMigrationRunnerService, - ) { - super(); - } - - async run( - _passedParam: string[], - options: RunWorkspaceMigrationsOptions, - ): Promise { - // TODO: run in a dedicated job + run queries in a transaction. - await this.workspaceMigrationService.insertStandardMigrations( - options.workspaceId, - ); - await this.workspaceMigrationRunnerService.executeMigrationFromPendingMigrations( - options.workspaceId, - ); - } - - // TODO: workspaceId should be optional and we should run migrations for all workspaces - @Option({ - flags: '-w, --workspace-id [workspace_id]', - description: 'workspace id', - required: true, - }) - parseWorkspaceId(value: string): string { - return value; - } -} diff --git a/packages/twenty-server/src/workspace/workspace-migration-runner/commands/workspace-migration-runner-commands.module.ts b/packages/twenty-server/src/workspace/workspace-migration-runner/commands/workspace-migration-runner-commands.module.ts deleted file mode 100644 index f8db8958f1..0000000000 --- a/packages/twenty-server/src/workspace/workspace-migration-runner/commands/workspace-migration-runner-commands.module.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Module } from '@nestjs/common'; - -import { WorkspaceMigrationModule } from 'src/metadata/workspace-migration/workspace-migration.module'; -import { WorkspaceMigrationRunnerModule } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.module'; - -import { RunWorkspaceMigrationsCommand } from './run-workspace-migrations.command'; - -@Module({ - imports: [WorkspaceMigrationModule, WorkspaceMigrationRunnerModule], - providers: [RunWorkspaceMigrationsCommand], -}) -export class WorkspaceMigrationRunnerCommandsModule {} diff --git a/packages/twenty-server/src/workspace/workspace-migration-runner/workspace-migration-runner.service.ts b/packages/twenty-server/src/workspace/workspace-migration-runner/workspace-migration-runner.service.ts index d2eb92e709..7f50884ecf 100644 --- a/packages/twenty-server/src/workspace/workspace-migration-runner/workspace-migration-runner.service.ts +++ b/packages/twenty-server/src/workspace/workspace-migration-runner/workspace-migration-runner.service.ts @@ -63,13 +63,11 @@ export class WorkspaceMigrationRunnerService { }, []); const queryRunner = workspaceDataSource?.createQueryRunner(); - const schemaName = - this.workspaceDataSourceService.getSchemaName(workspaceId); // Loop over each migration and create or update the table // TODO: Should be done in a transaction for (const migration of flattenedPendingMigrations) { - await this.handleTableChanges(queryRunner, schemaName, migration); + await this.handleTableChanges(queryRunner, migration); } // Update appliedAt date for each migration @@ -98,17 +96,20 @@ export class WorkspaceMigrationRunnerService { */ private async handleTableChanges( queryRunner: QueryRunner, - schemaName: string, tableMigration: WorkspaceMigrationTableAction, ) { switch (tableMigration.action) { case 'create': - await this.createTable(queryRunner, schemaName, tableMigration.name); + await this.createTable( + queryRunner, + tableMigration.schemaName, + tableMigration.name, + ); break; case 'alter': await this.handleColumnChanges( queryRunner, - schemaName, + tableMigration.schemaName, tableMigration.name, tableMigration?.columns, ); @@ -180,7 +181,7 @@ export class WorkspaceMigrationRunnerService { ); break; case WorkspaceMigrationColumnActionType.RELATION: - await this.createForeignKey( + await this.createRelation( queryRunner, schemaName, tableName, @@ -279,10 +280,9 @@ export class WorkspaceMigrationRunnerService { isNullable: migrationColumn.alteredColumnDefinition.isNullable, }), ); - // } } - private async createForeignKey( + private async createRelation( queryRunner: QueryRunner, schemaName: string, tableName: string, @@ -293,6 +293,7 @@ export class WorkspaceMigrationRunnerService { new TableForeignKey({ columnNames: [migrationColumn.columnName], referencedColumnNames: [migrationColumn.referencedTableColumnName], + referencedSchema: migrationColumn.referencedSchema, referencedTableName: migrationColumn.referencedTableName, onDelete: 'CASCADE', }), diff --git a/packages/twenty-server/src/workspace/workspace-query-builder/factories/relation-field-alias.factory.ts b/packages/twenty-server/src/workspace/workspace-query-builder/factories/relation-field-alias.factory.ts index d17e42abcf..3704ba13af 100644 --- a/packages/twenty-server/src/workspace/workspace-query-builder/factories/relation-field-alias.factory.ts +++ b/packages/twenty-server/src/workspace/workspace-query-builder/factories/relation-field-alias.factory.ts @@ -104,12 +104,12 @@ export class RelationFieldAliasFactory { ); return ` - ${fieldKey}: ${referencedObjectMetadata.targetTableName}Collection${ + ${fieldKey}: ${referencedObjectMetadata.targetTableName}Collection${ argsString ? `(${argsString})` : '' } { - ${fieldsString} - } - `; + ${fieldsString} + } + `; } let relationAlias = fieldMetadata.isCustom ? `${fieldKey}: ${fieldMetadata.targetColumnMap.value}` diff --git a/packages/twenty-server/src/workspace/workspace-schema-builder/graphql-types/scalars/index.ts b/packages/twenty-server/src/workspace/workspace-schema-builder/graphql-types/scalars/index.ts index e26a171825..fa9b1f0f4a 100644 --- a/packages/twenty-server/src/workspace/workspace-schema-builder/graphql-types/scalars/index.ts +++ b/packages/twenty-server/src/workspace/workspace-schema-builder/graphql-types/scalars/index.ts @@ -1,6 +1,6 @@ +import { CursorScalarType } from './cursor.scalar'; import { BigFloatScalarType } from './big-float.scalar'; import { BigIntScalarType } from './big-int.scalar'; -import { CursorScalarType } from './cursor.scalar'; import { DateScalarType } from './date.scalar'; import { DateTimeScalarType } from './date-time.scalar'; import { TimeScalarType } from './time.scalar'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator.ts new file mode 100644 index 0000000000..430e0604be --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator.ts @@ -0,0 +1,82 @@ +import { + FieldMetadataDecoratorParams, + ReflectFieldMetadata, +} from 'src/workspace/workspace-sync-metadata/interfaces/reflect-field-metadata.interface'; +import { GateDecoratorParams } from 'src/workspace/workspace-sync-metadata/interfaces/gate-decorator.interface'; + +import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; +import { generateTargetColumnMap } from 'src/metadata/field-metadata/utils/generate-target-column-map.util'; +import { generateDefaultValue } from 'src/metadata/field-metadata/utils/generate-default-value'; +import { TypedReflect } from 'src/utils/typed-reflect'; + +export function FieldMetadata( + params: FieldMetadataDecoratorParams, +): PropertyDecorator { + return (target: object, fieldKey: string) => { + const existingFieldMetadata = + TypedReflect.getMetadata('fieldMetadata', target.constructor) ?? {}; + const isNullable = + TypedReflect.getMetadata('isNullable', target, fieldKey) ?? false; + const isSystem = + TypedReflect.getMetadata('isSystem', target, fieldKey) ?? false; + const gate = TypedReflect.getMetadata('gate', target, fieldKey); + const { joinColumn, ...restParams } = params; + + TypedReflect.defineMetadata( + 'fieldMetadata', + { + ...existingFieldMetadata, + [fieldKey]: generateFieldMetadata( + restParams, + fieldKey, + isNullable, + isSystem, + gate, + ), + ...(joinColumn && restParams.type === FieldMetadataType.RELATION + ? { + [joinColumn]: generateFieldMetadata( + { + ...restParams, + type: FieldMetadataType.UUID, + label: `${restParams.label} id (foreign key)`, + description: `${restParams.description} id foreign key`, + defaultValue: null, + }, + joinColumn, + isNullable, + true, + gate, + ), + } + : {}), + }, + target.constructor, + ); + }; +} + +function generateFieldMetadata( + params: FieldMetadataDecoratorParams, + fieldKey: string, + isNullable: boolean, + isSystem: boolean, + gate: GateDecoratorParams | undefined = undefined, +): ReflectFieldMetadata[string] { + const targetColumnMap = generateTargetColumnMap(params.type, false, fieldKey); + const defaultValue = params.defaultValue ?? generateDefaultValue(params.type); + + return { + name: fieldKey, + ...params, + targetColumnMap: JSON.stringify(targetColumnMap), + isNullable: params.type === FieldMetadataType.RELATION ? true : isNullable, + isSystem, + isCustom: false, + // TODO: handle options + stringify for the diff. + description: params.description, + icon: params.icon, + defaultValue: defaultValue ? JSON.stringify(defaultValue) : null, + gate, + }; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/gate.decorator.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/gate.decorator.ts new file mode 100644 index 0000000000..c5753ed74e --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/gate.decorator.ts @@ -0,0 +1,13 @@ +import { GateDecoratorParams } from 'src/workspace/workspace-sync-metadata/interfaces/gate-decorator.interface'; + +import { TypedReflect } from 'src/utils/typed-reflect'; + +export function Gate(metadata: GateDecoratorParams) { + return function (target: object, fieldKey?: string) { + if (fieldKey) { + TypedReflect.defineMetadata('gate', metadata, target, fieldKey); + } else { + TypedReflect.defineMetadata('gate', metadata, target); + } + }; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator.ts new file mode 100644 index 0000000000..3630d752ed --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator.ts @@ -0,0 +1,7 @@ +import { TypedReflect } from 'src/utils/typed-reflect'; + +export function IsNullable() { + return function (target: object, fieldKey: string) { + TypedReflect.defineMetadata('isNullable', true, target, fieldKey); + }; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/is-system.decorator.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/is-system.decorator.ts new file mode 100644 index 0000000000..8d21db2dec --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/is-system.decorator.ts @@ -0,0 +1,11 @@ +import { TypedReflect } from 'src/utils/typed-reflect'; + +export function IsSystem() { + return function (target: object, fieldKey?: string) { + if (fieldKey) { + TypedReflect.defineMetadata('isSystem', true, target, fieldKey); + } else { + TypedReflect.defineMetadata('isSystem', true, target); + } + }; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/metadata.decorator.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/metadata.decorator.ts deleted file mode 100644 index c34c36cceb..0000000000 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/metadata.decorator.ts +++ /dev/null @@ -1,210 +0,0 @@ -import camelCase from 'lodash.camelcase'; -import 'reflect-metadata'; - -import { FieldMetadataDefaultValue } from 'src/metadata/field-metadata/interfaces/field-metadata-default-value.interface'; - -import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { generateTargetColumnMap } from 'src/metadata/field-metadata/utils/generate-target-column-map.util'; -import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { generateDefaultValue } from 'src/metadata/field-metadata/utils/generate-default-value'; - -export interface FieldMetadataDecorator { - type: T; - label: string; - description?: string | null; - icon?: string | null; - defaultValue?: FieldMetadataDefaultValue | null; - joinColumn?: string; -} - -export type ObjectMetadataDecorator = { - namePlural: string; - labelSingular: string; - labelPlural: string; - description?: string | null; - icon?: string | null; -}; - -export type RelationMetadataDecorator = { - type: RelationMetadataType; - objectName: string; - inverseSideFieldName?: string; -}; - -export type GateDecorator = { - featureFlag: string; -}; - -function convertClassNameToObjectMetadataName(name: string): string { - const classSuffix = 'ObjectMetadata'; - let objectName = camelCase(name); - - if (objectName.endsWith(classSuffix)) { - objectName = objectName.slice(0, -classSuffix.length); - } - - return objectName; -} - -export function ObjectMetadata( - metadata: ObjectMetadataDecorator, -): ClassDecorator { - return (target) => { - const isSystem = Reflect.getMetadata('isSystem', target) || false; - - const gate = Reflect.getMetadata('gate', target) || undefined; - - const objectName = convertClassNameToObjectMetadataName(target.name); - - Reflect.defineMetadata( - 'objectMetadata', - { - nameSingular: objectName, - ...metadata, - gate, - targetTableName: objectName, - isSystem, - isCustom: false, - description: metadata.description ?? null, - icon: metadata.icon ?? null, - }, - target, - ); - }; -} - -export function IsNullable() { - return function (target: object, fieldKey: string) { - Reflect.defineMetadata('isNullable', true, target, fieldKey); - }; -} - -export function IsSystem() { - return function (target: object, fieldKey?: string) { - if (fieldKey) { - Reflect.defineMetadata('isSystem', true, target, fieldKey); - } else { - Reflect.defineMetadata('isSystem', true, target); - } - }; -} - -export function Gate(metadata: GateDecorator) { - return function (target: object, fieldKey?: string) { - if (fieldKey) { - Reflect.defineMetadata('gate', metadata, target, fieldKey); - } else { - Reflect.defineMetadata('gate', metadata, target); - } - }; -} - -export function FieldMetadata( - metadata: FieldMetadataDecorator, -): PropertyDecorator { - return (target: object, fieldKey: string) => { - const existingFieldMetadata = - Reflect.getMetadata('fieldMetadata', target.constructor) || {}; - - const isNullable = - Reflect.getMetadata('isNullable', target, fieldKey) || false; - - const isSystem = Reflect.getMetadata('isSystem', target, fieldKey) || false; - - const gate = Reflect.getMetadata('gate', target, fieldKey) || undefined; - - const { joinColumn, ...fieldMetadata } = metadata; - - Reflect.defineMetadata( - 'fieldMetadata', - { - ...existingFieldMetadata, - [fieldKey]: generateFieldMetadata( - fieldMetadata, - fieldKey, - isNullable, - isSystem, - gate, - ), - ...(joinColumn && fieldMetadata.type === FieldMetadataType.RELATION - ? { - [joinColumn]: generateFieldMetadata( - { - ...fieldMetadata, - type: FieldMetadataType.UUID, - label: `${fieldMetadata.label} id (foreign key)`, - description: `${fieldMetadata.description} id foreign key`, - defaultValue: null, - }, - joinColumn, - isNullable, - true, - gate, - ), - } - : {}), - }, - target.constructor, - ); - }; -} - -function generateFieldMetadata( - metadata: FieldMetadataDecorator, - fieldKey: string, - isNullable: boolean, - isSystem: boolean, - gate: GateDecorator | undefined = undefined, -) { - const targetColumnMap = JSON.stringify( - generateTargetColumnMap(metadata.type, false, fieldKey), - ); - const defaultValue = - metadata.defaultValue ?? generateDefaultValue(metadata.type); - - return { - name: fieldKey, - ...metadata, - targetColumnMap: targetColumnMap, - isNullable: - metadata.type === FieldMetadataType.RELATION ? true : isNullable, - isSystem, - isCustom: false, - options: null, // TODO: handle options + stringify for the diff. - description: metadata.description ?? null, - icon: metadata.icon ?? null, - defaultValue: defaultValue ? JSON.stringify(defaultValue) : null, - gate, - }; -} - -export function RelationMetadata( - metadata: RelationMetadataDecorator, -): PropertyDecorator { - return (target: object, fieldKey: string) => { - const existingRelationMetadata = - Reflect.getMetadata('relationMetadata', target.constructor) || []; - - const gate = Reflect.getMetadata('gate', target, fieldKey) || undefined; - - const objectName = convertClassNameToObjectMetadataName( - target.constructor.name, - ); - - Reflect.defineMetadata( - 'relationMetadata', - [ - ...existingRelationMetadata, - { - type: metadata.type, - fromObjectNameSingular: objectName, - toObjectNameSingular: metadata.objectName, - fromFieldMetadataName: fieldKey, - toFieldMetadataName: metadata.inverseSideFieldName ?? objectName, - gate, - }, - ], - target.constructor, - ); - }; -} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator.ts new file mode 100644 index 0000000000..bee7c04057 --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator.ts @@ -0,0 +1,29 @@ +import { ObjectMetadataDecoratorParams } from 'src/workspace/workspace-sync-metadata/interfaces/reflect-object-metadata.interface'; + +import { TypedReflect } from 'src/utils/typed-reflect'; +import { convertClassNameToObjectMetadataName } from 'src/workspace/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util'; + +export function ObjectMetadata( + params: ObjectMetadataDecoratorParams, +): ClassDecorator { + return (target) => { + const isSystem = TypedReflect.getMetadata('isSystem', target) ?? false; + const gate = TypedReflect.getMetadata('gate', target); + const objectName = convertClassNameToObjectMetadataName(target.name); + + TypedReflect.defineMetadata( + 'objectMetadata', + { + nameSingular: objectName, + ...params, + targetTableName: objectName, + isSystem, + isCustom: false, + description: params.description, + icon: params.icon, + gate, + }, + target, + ); + }; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator.ts new file mode 100644 index 0000000000..142061671c --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator.ts @@ -0,0 +1,35 @@ +import 'reflect-metadata'; + +import { RelationMetadataDecoratorParams } from 'src/workspace/workspace-sync-metadata/interfaces/reflect-relation-metadata.interface'; + +import { TypedReflect } from 'src/utils/typed-reflect'; +import { convertClassNameToObjectMetadataName } from 'src/workspace/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util'; + +export function RelationMetadata( + params: RelationMetadataDecoratorParams, +): PropertyDecorator { + return (target: object, fieldKey: string) => { + const existingRelationMetadata = + TypedReflect.getMetadata('relationMetadata', target.constructor) ?? []; + const gate = TypedReflect.getMetadata('gate', target, fieldKey); + const objectName = convertClassNameToObjectMetadataName( + target.constructor.name, + ); + + Reflect.defineMetadata( + 'relationMetadata', + [ + ...existingRelationMetadata, + { + type: params.type, + fromObjectNameSingular: objectName, + toObjectNameSingular: params.objectName, + fromFieldMetadataName: fieldKey, + toFieldMetadataName: params.inverseSideFieldName ?? objectName, + gate, + }, + ], + target.constructor, + ); + }; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/gate-decorator.interface.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/gate-decorator.interface.ts new file mode 100644 index 0000000000..badb9b8fb6 --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/gate-decorator.interface.ts @@ -0,0 +1,3 @@ +export interface GateDecoratorParams { + featureFlag: string; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/mapped-metadata.interface.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/mapped-metadata.interface.ts new file mode 100644 index 0000000000..70c9c41751 --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/mapped-metadata.interface.ts @@ -0,0 +1,19 @@ +import { PartialFieldMetadata } from 'src/workspace/workspace-sync-metadata/interfaces/partial-field-metadata.interface'; +import { PartialObjectMetadata } from 'src/workspace/workspace-sync-metadata/interfaces/partial-object-metadata.interface'; + +import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity'; +import { FieldMetadataEntity } from 'src/metadata/field-metadata/field-metadata.entity'; + +export type MappedFieldMetadata = Record; + +export interface MappedObjectMetadata + extends Omit { + fields: MappedFieldMetadata; +} + +export type MappedFieldMetadataEntity = Record; + +export interface MappedObjectMetadataEntity + extends Omit { + fields: MappedFieldMetadataEntity; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/partial-field-metadata.interface.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/partial-field-metadata.interface.ts new file mode 100644 index 0000000000..6e21f7c184 --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/partial-field-metadata.interface.ts @@ -0,0 +1,6 @@ +import { ReflectFieldMetadata } from 'src/workspace/workspace-sync-metadata/interfaces/reflect-field-metadata.interface'; + +export type PartialFieldMetadata = ReflectFieldMetadata[string] & { + workspaceId: string; + objectMetadataId?: string; +}; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/partial-object-metadata.interface.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/partial-object-metadata.interface.ts new file mode 100644 index 0000000000..0e12d1bcd5 --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/partial-object-metadata.interface.ts @@ -0,0 +1,8 @@ +import { PartialFieldMetadata } from 'src/workspace/workspace-sync-metadata/interfaces/partial-field-metadata.interface'; +import { ReflectObjectMetadata } from 'src/workspace/workspace-sync-metadata/interfaces/reflect-object-metadata.interface'; + +export type PartialObjectMetadata = ReflectObjectMetadata & { + workspaceId: string; + dataSourceId: string; + fields: PartialFieldMetadata[]; +}; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-field-metadata.interface.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-field-metadata.interface.ts new file mode 100644 index 0000000000..48fad391c0 --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-field-metadata.interface.ts @@ -0,0 +1,32 @@ +import { FieldMetadataDefaultValue } from 'src/metadata/field-metadata/interfaces/field-metadata-default-value.interface'; +import { GateDecoratorParams } from 'src/workspace/workspace-sync-metadata/interfaces/gate-decorator.interface'; + +import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; + +export interface FieldMetadataDecoratorParams< + T extends FieldMetadataType | 'default', +> { + type: T; + label: string; + description?: string; + icon?: string; + defaultValue?: FieldMetadataDefaultValue; + joinColumn?: string; +} + +export interface ReflectFieldMetadata { + [key: string]: Omit< + FieldMetadataDecoratorParams<'default'>, + 'defaultValue' | 'type' + > & { + name: string; + type: FieldMetadataType; + targetColumnMap: string; + isNullable: boolean; + isSystem: boolean; + isCustom: boolean; + description?: string; + defaultValue: string | null; + gate?: GateDecoratorParams; + }; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-object-metadata.interface.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-object-metadata.interface.ts new file mode 100644 index 0000000000..10bbd3d5c2 --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-object-metadata.interface.ts @@ -0,0 +1,17 @@ +import { GateDecoratorParams } from 'src/workspace/workspace-sync-metadata/interfaces/gate-decorator.interface'; + +export interface ObjectMetadataDecoratorParams { + namePlural: string; + labelSingular: string; + labelPlural: string; + description?: string; + icon?: string; +} + +export interface ReflectObjectMetadata extends ObjectMetadataDecoratorParams { + nameSingular: string; + targetTableName: string; + isSystem: boolean; + isCustom: boolean; + gate?: GateDecoratorParams; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-relation-metadata.interface.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-relation-metadata.interface.ts new file mode 100644 index 0000000000..ee9d7af5f7 --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/interfaces/reflect-relation-metadata.interface.ts @@ -0,0 +1,18 @@ +import { GateDecoratorParams } from 'src/workspace/workspace-sync-metadata/interfaces/gate-decorator.interface'; + +import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; + +export interface RelationMetadataDecoratorParams { + type: RelationMetadataType; + objectName: string; + inverseSideFieldName?: string; +} + +export interface ReflectRelationMetadata { + type: RelationMetadataType; + fromObjectNameSingular: string; + toObjectNameSingular: string; + fromFieldMetadataName: string; + toFieldMetadataName: string; + gate?: GateDecoratorParams; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/metadata.parser.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/reflective-metadata.factory.ts similarity index 58% rename from packages/twenty-server/src/workspace/workspace-sync-metadata/utils/metadata.parser.ts rename to packages/twenty-server/src/workspace/workspace-sync-metadata/reflective-metadata.factory.ts index c62c15b92e..88da5a5097 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/metadata.parser.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/reflective-metadata.factory.ts @@ -1,18 +1,25 @@ +import { Injectable } from '@nestjs/common'; + import assert from 'assert'; -import { FieldMetadataEntity } from 'src/metadata/field-metadata/field-metadata.entity'; -import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity'; -import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; +import { PartialObjectMetadata } from 'src/workspace/workspace-sync-metadata/interfaces/partial-object-metadata.interface'; +import { MappedObjectMetadataEntity } from 'src/workspace/workspace-sync-metadata/interfaces/mapped-metadata.interface'; -export class MetadataParser { - static parseMetadata( +import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; +import { TypedReflect } from 'src/utils/typed-reflect'; +import { isGatedAndNotEnabled } from 'src/workspace/workspace-sync-metadata/utils/is-gate-and-not-enabled.util'; + +@Injectable() +export class ReflectiveMetadataFactory { + async createObjectMetadata( metadata: typeof BaseObjectMetadata, workspaceId: string, - dataSourceId: string, + defaultDataSourceId: string, workspaceFeatureFlagsMap: Record, - ): ObjectMetadataEntity | undefined { - const objectMetadata = Reflect.getMetadata('objectMetadata', metadata); - const fieldMetadata = Reflect.getMetadata('fieldMetadata', metadata); + ): Promise { + const objectMetadata = TypedReflect.getMetadata('objectMetadata', metadata); + const fieldMetadata = + TypedReflect.getMetadata('fieldMetadata', metadata) ?? {}; if (!objectMetadata) { throw new Error( @@ -31,47 +38,48 @@ export class MetadataParser { return { ...objectMetadata, workspaceId, - dataSourceId, - fields: fields.map((field: FieldMetadataEntity) => ({ + dataSourceId: defaultDataSourceId, + fields: fields.map((field) => ({ ...field, workspaceId, isSystem: objectMetadata.isSystem || field.isSystem, - defaultValue: field.defaultValue || null, - options: field.options || null, + defaultValue: field.defaultValue, })), }; } - static parseAllMetadata( + async createObjectMetadataCollection( metadataCollection: (typeof BaseObjectMetadata)[], workspaceId: string, dataSourceId: string, workspaceFeatureFlagsMap: Record, - ): ObjectMetadataEntity[] { - return metadataCollection - .map((metadata) => - MetadataParser.parseMetadata( - metadata, - workspaceId, - dataSourceId, - workspaceFeatureFlagsMap, - ), - ) - .filter( - (metadata): metadata is ObjectMetadataEntity => metadata !== undefined, - ); + ) { + const metadataPromises = metadataCollection.map((metadata) => + this.createObjectMetadata( + metadata, + workspaceId, + dataSourceId, + workspaceFeatureFlagsMap, + ), + ); + const resolvedMetadata = await Promise.all(metadataPromises); + + return resolvedMetadata.filter( + (metadata): metadata is PartialObjectMetadata => !!metadata, + ); } - static parseRelationMetadata( + createRelationMetadata( metadata: typeof BaseObjectMetadata, workspaceId: string, - objectMetadataFromDB: Record, + objectMetadataFromDB: Record, workspaceFeatureFlagsMap: Record, ) { - const objectMetadata = Reflect.getMetadata('objectMetadata', metadata); - const relationMetadata = Reflect.getMetadata('relationMetadata', metadata); - - if (!relationMetadata) return []; + const objectMetadata = TypedReflect.getMetadata('objectMetadata', metadata); + const relationMetadata = TypedReflect.getMetadata( + 'relationMetadata', + metadata, + ); if (!objectMetadata) { throw new Error( @@ -79,7 +87,10 @@ export class MetadataParser { ); } - if (isGatedAndNotEnabled(objectMetadata, workspaceFeatureFlagsMap)) { + if ( + !relationMetadata || + isGatedAndNotEnabled(objectMetadata, workspaceFeatureFlagsMap) + ) { return []; } @@ -94,7 +105,7 @@ export class MetadataParser { assert( fromObjectMetadata, `Object ${relation.fromObjectNameSingular} not found in DB - for fromRelation defined in class ${objectMetadata.nameSingular}`, + for relation FROM defined in class ${objectMetadata.nameSingular}`, ); const toObjectMetadata = @@ -103,7 +114,7 @@ export class MetadataParser { assert( toObjectMetadata, `Object ${relation.toObjectNameSingular} not found in DB - for toRelation defined in class ${objectMetadata.nameSingular}`, + for relation TO defined in class ${objectMetadata.nameSingular}`, ); const fromFieldMetadata = @@ -112,7 +123,7 @@ export class MetadataParser { assert( fromFieldMetadata, `Field ${relation.fromFieldMetadataName} not found in object ${relation.fromObjectNameSingular} - for fromRelation defined in class ${objectMetadata.nameSingular}`, + for relation FROM defined in class ${objectMetadata.nameSingular}`, ); const toFieldMetadata = @@ -121,7 +132,7 @@ export class MetadataParser { assert( toFieldMetadata, `Field ${relation.toFieldMetadataName} not found in object ${relation.toObjectNameSingular} - for toRelation defined in class ${objectMetadata.nameSingular}`, + for relation TO defined in class ${objectMetadata.nameSingular}`, ); return { @@ -135,14 +146,14 @@ export class MetadataParser { }); } - static parseAllRelations( + createRelationMetadataCollection( metadataCollection: (typeof BaseObjectMetadata)[], workspaceId: string, - objectMetadataFromDB: Record, + objectMetadataFromDB: Record, workspaceFeatureFlagsMap: Record, ) { return metadataCollection.flatMap((metadata) => - MetadataParser.parseRelationMetadata( + this.createRelationMetadata( metadata, workspaceId, objectMetadataFromDB, @@ -151,14 +162,3 @@ export class MetadataParser { ); } } - -function isGatedAndNotEnabled( - metadata, - workspaceFeatureFlagsMap: Record, -): boolean { - const featureFlagValue = - metadata.gate?.featureFlag && - workspaceFeatureFlagsMap[metadata.gate.featureFlag]; - - return metadata.gate?.featureFlag !== undefined && !featureFlagValue; -} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/activity-target.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/activity-target.object-metadata.ts index 0602ae0ba2..51ab1bef92 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/activity-target.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/activity-target.object-metadata.ts @@ -1,10 +1,8 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - ObjectMetadata, - FieldMetadata, - IsSystem, - IsNullable, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { ActivityObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/activity.object-metadata'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { CompanyObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/activity.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/activity.object-metadata.ts index a276428feb..3f12242245 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/activity.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/activity.object-metadata.ts @@ -1,12 +1,10 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - IsNullable, - FieldMetadata, - RelationMetadata, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; +import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator'; import { ActivityTargetObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/activity-target.object-metadata'; import { AttachmentObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/attachment.object-metadata'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/api-key.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/api-key.object-metadata.ts index 6a3235011f..0f30b86ab4 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/api-key.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/api-key.object-metadata.ts @@ -1,10 +1,8 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - ObjectMetadata, - FieldMetadata, - IsNullable, - IsSystem, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; @ObjectMetadata({ diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/attachment.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/attachment.object-metadata.ts index 7220de35b1..bc299edc1f 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/attachment.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/attachment.object-metadata.ts @@ -1,10 +1,8 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, - IsNullable, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { ActivityObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/activity.object-metadata'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { CompanyObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata.ts index e7f791d237..bfd8c5fc4e 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata.ts @@ -1,15 +1,11 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - FieldMetadata, - IsSystem, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; export abstract class BaseObjectMetadata { @FieldMetadata({ type: FieldMetadataType.UUID, label: 'Id', - icon: null, - description: null, defaultValue: { type: 'uuid' }, }) @IsSystem() @@ -18,7 +14,6 @@ export abstract class BaseObjectMetadata { @FieldMetadata({ type: FieldMetadataType.DATE_TIME, label: 'Creation date', - description: null, icon: 'IconCalendar', defaultValue: { type: 'now' }, }) @@ -27,7 +22,6 @@ export abstract class BaseObjectMetadata { @FieldMetadata({ type: FieldMetadataType.DATE_TIME, label: 'Update date', - description: null, icon: 'IconCalendar', defaultValue: { type: 'now' }, }) diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/comment.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/comment.object-metadata.ts index 4326b454c4..81dd61e7ee 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/comment.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/comment.object-metadata.ts @@ -1,9 +1,7 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { ActivityObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/activity.object-metadata'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { WorkspaceMemberObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata.ts index 915ef8b7a4..52db0a3ca5 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata.ts @@ -2,12 +2,10 @@ import { CurrencyMetadata } from 'src/metadata/field-metadata/composite-types/cu import { LinkMetadata } from 'src/metadata/field-metadata/composite-types/link.composite-type'; import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { - ObjectMetadata, - FieldMetadata, - IsNullable, - RelationMetadata, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; +import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator'; import { ActivityTargetObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/activity-target.object-metadata'; import { AttachmentObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/attachment.object-metadata'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/connected-account.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/connected-account.object-metadata.ts index 5082e1bf15..7decdd0838 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/connected-account.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/connected-account.object-metadata.ts @@ -1,13 +1,11 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, - IsNullable, - RelationMetadata, - Gate, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; +import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { MessageChannelObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-channel.object-metadata'; import { WorkspaceMemberObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/favorite.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/favorite.object-metadata.ts index aba76eb951..585387aa14 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/favorite.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/favorite.object-metadata.ts @@ -1,10 +1,8 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, - IsNullable, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { CompanyObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata'; import { PersonObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-channel.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-channel.object-metadata.ts index 83b878d07b..98d512d861 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-channel.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-channel.object-metadata.ts @@ -1,13 +1,11 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, - IsNullable, - RelationMetadata, - Gate, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; +import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { ConnectedAccountObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/connected-account.object-metadata'; import { MessageThreadObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-thread.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-recipient.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-recipient.object-metadata.ts index a45455dfe4..6b7f2f3e67 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-recipient.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-recipient.object-metadata.ts @@ -1,11 +1,9 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, - IsNullable, - Gate, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { MessageObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message.object-metadata'; import { PersonObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-thread.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-thread.object-metadata.ts index ad7f3961d8..5b2215bd8a 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-thread.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message-thread.object-metadata.ts @@ -1,13 +1,11 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, - IsNullable, - RelationMetadata, - Gate, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; +import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { MessageChannelObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-channel.object-metadata'; import { MessageObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message.object-metadata.ts index 929ef2e954..f67bfb54dc 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/message.object-metadata.ts @@ -1,13 +1,11 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, - IsNullable, - RelationMetadata, - Gate, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; +import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { MessageRecipientObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-recipient.object-metadata'; import { MessageThreadObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-thread.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/opportunity.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/opportunity.object-metadata.ts index 2d4ad44401..4ce7818185 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/opportunity.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/opportunity.object-metadata.ts @@ -1,10 +1,8 @@ import { CurrencyMetadata } from 'src/metadata/field-metadata/composite-types/currency.composite-type'; import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - ObjectMetadata, - FieldMetadata, - IsNullable, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { CompanyObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata'; import { PersonObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata.ts index 3839ea7ef2..e9dc4a3c24 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata.ts @@ -2,14 +2,12 @@ import { FullNameMetadata } from 'src/metadata/field-metadata/composite-types/fu import { LinkMetadata } from 'src/metadata/field-metadata/composite-types/link.composite-type'; import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { - ObjectMetadata, - FieldMetadata, - IsNullable, - RelationMetadata, - IsSystem, - Gate, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; +import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator'; import { ActivityTargetObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/activity-target.object-metadata'; import { AttachmentObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/attachment.object-metadata'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/pipeline-step.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/pipeline-step.object-metadata.ts index 1b922ceec1..8be3361da4 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/pipeline-step.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/pipeline-step.object-metadata.ts @@ -1,12 +1,10 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { - ObjectMetadata, - FieldMetadata, - IsNullable, - IsSystem, - RelationMetadata, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; +import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { OpportunityObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/opportunity.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-field.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-field.object-metadata.ts index 878a301cca..5104d686b6 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-field.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-field.object-metadata.ts @@ -1,10 +1,8 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, - IsNullable, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { ViewObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/view.object-metadata'; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-filter.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-filter.object-metadata.ts index 668afccfcc..d6aca3ff7f 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-filter.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-filter.object-metadata.ts @@ -1,10 +1,8 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, - IsNullable, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { ViewObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/view.object-metadata'; @@ -21,7 +19,6 @@ export class ViewFilterObjectMetadata extends BaseObjectMetadata { type: FieldMetadataType.UUID, label: 'Field Metadata Id', description: 'View Filter target field', - icon: null, }) fieldMetadataId: string; @@ -29,7 +26,6 @@ export class ViewFilterObjectMetadata extends BaseObjectMetadata { type: FieldMetadataType.TEXT, label: 'Operand', description: 'View Filter operand', - icon: null, defaultValue: { value: 'Contains' }, }) operand: string; @@ -38,7 +34,6 @@ export class ViewFilterObjectMetadata extends BaseObjectMetadata { type: FieldMetadataType.TEXT, label: 'Value', description: 'View Filter value', - icon: null, defaultValue: { value: '' }, }) value: string; @@ -47,7 +42,6 @@ export class ViewFilterObjectMetadata extends BaseObjectMetadata { type: FieldMetadataType.TEXT, label: 'Display Value', description: 'View Filter Display Value', - icon: null, defaultValue: { value: '' }, }) displayValue: string; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-sort.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-sort.object-metadata.ts index 17cbf741a8..a0a00b54db 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-sort.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view-sort.object-metadata.ts @@ -1,10 +1,8 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - ObjectMetadata, - FieldMetadata, - IsNullable, - IsSystem, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { ViewObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/view.object-metadata'; @@ -29,7 +27,6 @@ export class ViewSortObjectMetadata extends BaseObjectMetadata { type: FieldMetadataType.TEXT, label: 'Direction', description: 'View Sort direction', - icon: null, defaultValue: { value: 'asc' }, }) direction: string; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view.object-metadata.ts index 0be6186702..ae8d915cde 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/view.object-metadata.ts @@ -1,12 +1,10 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, - RelationMetadata, - IsNullable, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; +import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { ViewFieldObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/view-field.object-metadata'; import { ViewFilterObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/view-filter.object-metadata'; @@ -25,7 +23,6 @@ export class ViewObjectMetadata extends BaseObjectMetadata { type: FieldMetadataType.TEXT, label: 'Name', description: 'View name', - icon: null, defaultValue: { value: '' }, }) name: string; @@ -34,7 +31,6 @@ export class ViewObjectMetadata extends BaseObjectMetadata { type: FieldMetadataType.UUID, label: 'Object Metadata Id', description: 'View target object', - icon: null, }) objectMetadataId: string; @@ -42,7 +38,6 @@ export class ViewObjectMetadata extends BaseObjectMetadata { type: FieldMetadataType.TEXT, label: 'Type', description: 'View type', - icon: null, defaultValue: { value: 'table' }, }) type: string; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/webhook.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/webhook.object-metadata.ts index 1e64c21d08..58412fb624 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/webhook.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/webhook.object-metadata.ts @@ -1,9 +1,7 @@ import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; @ObjectMetadata({ diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata.ts index e2256f26a1..afc2c37fc5 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata.ts @@ -1,14 +1,12 @@ import { FullNameMetadata } from 'src/metadata/field-metadata/composite-types/full-name.composite-type'; import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { - ObjectMetadata, - IsSystem, - FieldMetadata, - IsNullable, - RelationMetadata, - Gate, -} from 'src/workspace/workspace-sync-metadata/decorators/metadata.decorator'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; +import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator'; import { ActivityObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/activity.object-metadata'; import { AttachmentObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/attachment.object-metadata'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; @@ -61,6 +59,14 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata { }) avatarUrl: string; + @FieldMetadata({ + type: FieldMetadataType.TEXT, + label: 'User Email', + description: 'Related user email address', + icon: 'IconMail', + }) + userEmail: string; + @FieldMetadata({ type: FieldMetadataType.UUID, label: 'User Id', diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util.ts new file mode 100644 index 0000000000..4ea82fe9dc --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util.ts @@ -0,0 +1,12 @@ +import { camelCase } from 'src/utils/camel-case'; + +export const convertClassNameToObjectMetadataName = (name: string): string => { + const classSuffix = 'ObjectMetadata'; + let objectName = camelCase(name); + + if (objectName.endsWith(classSuffix)) { + objectName = objectName.slice(0, -classSuffix.length); + } + + return objectName; +}; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/is-gate-and-not-enabled.util.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/is-gate-and-not-enabled.util.ts new file mode 100644 index 0000000000..60348141ce --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/is-gate-and-not-enabled.util.ts @@ -0,0 +1,10 @@ +export const isGatedAndNotEnabled = ( + metadata, + workspaceFeatureFlagsMap: Record, +): boolean => { + const featureFlagValue = + metadata.gate?.featureFlag && + workspaceFeatureFlagsMap[metadata.gate.featureFlag]; + + return metadata.gate?.featureFlag !== undefined && !featureFlagValue; +}; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/sync-metadata.util.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/sync-metadata.util.ts index 1b030adf44..0b30e1ee3a 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/sync-metadata.util.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/utils/sync-metadata.util.ts @@ -1,4 +1,6 @@ -import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity'; +import { FieldMetadataDefaultValue } from 'src/metadata/field-metadata/interfaces/field-metadata-default-value.interface'; +import { FieldMetadataOptions } from 'src/metadata/field-metadata/interfaces/field-metadata-options.interface'; +import { FieldMetadataTargetColumnMap } from 'src/metadata/field-metadata/interfaces/field-metadata-target-column-map.interface'; /** * This utility function filters out properties from an object based on a list of properties to ignore. @@ -28,9 +30,12 @@ export const filterIgnoredProperties = ( * @param arr - The array of ObjectMetadataEntity objects to convert. * @returns A map of object metadata, with nameSingular as the key and the object as the value. */ -export const mapObjectMetadataByUniqueIdentifier = ( - arr: ObjectMetadataEntity[], -) => { +export const mapObjectMetadataByUniqueIdentifier = < + T extends { nameSingular: string; fields: U[] }, + U extends { name: string }, +>( + arr: T[], +): Record & { fields: Record }> => { return arr.reduce((acc, curr) => { acc[curr.nameSingular] = { ...curr, @@ -38,29 +43,41 @@ export const mapObjectMetadataByUniqueIdentifier = ( acc[curr.name] = curr; return acc; - }, {}), + }, {} as Record), }; return acc; - }, {}); + }, {} as Record & { fields: Record }>); }; -export const convertStringifiedFieldsToJSON = (fieldMetadata) => { +export const convertStringifiedFieldsToJSON = < + T extends { + targetColumnMap?: string | null; + defaultValue?: string | null; + options?: string | null; + }, +>( + fieldMetadata: T, +): T & { + targetColumnMap?: FieldMetadataTargetColumnMap; + defaultValue?: FieldMetadataDefaultValue; + options?: FieldMetadataOptions; +} => { if (fieldMetadata.targetColumnMap) { - fieldMetadata.targetColumnMap = JSON.parse( - fieldMetadata.targetColumnMap as unknown as string, - ); - } - if (fieldMetadata.defaultValue) { - fieldMetadata.defaultValue = JSON.parse( - fieldMetadata.defaultValue as unknown as string, - ); - } - if (fieldMetadata.options) { - fieldMetadata.options = JSON.parse( - fieldMetadata.options as unknown as string, - ); + fieldMetadata.targetColumnMap = JSON.parse(fieldMetadata.targetColumnMap); } - return fieldMetadata; + if (fieldMetadata.defaultValue) { + fieldMetadata.defaultValue = JSON.parse(fieldMetadata.defaultValue); + } + + if (fieldMetadata.options) { + fieldMetadata.options = JSON.parse(fieldMetadata.options); + } + + return fieldMetadata as T & { + targetColumnMap?: FieldMetadataTargetColumnMap; + defaultValue?: FieldMetadataDefaultValue; + options?: FieldMetadataOptions; + }; }; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/workspace-sync-metadata.module.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/workspace-sync-metadata.module.ts index a00ab068e3..dfbfb6fda1 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/workspace-sync-metadata.module.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/workspace-sync-metadata.module.ts @@ -8,6 +8,7 @@ import { RelationMetadataEntity } from 'src/metadata/relation-metadata/relation- import { WorkspaceMigrationEntity } from 'src/metadata/workspace-migration/workspace-migration.entity'; import { WorkspaceMigrationModule } from 'src/metadata/workspace-migration/workspace-migration.module'; import { WorkspaceMigrationRunnerModule } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.module'; +import { ReflectiveMetadataFactory } from 'src/workspace/workspace-sync-metadata/reflective-metadata.factory'; import { WorkspaceSyncMetadataService } from 'src/workspace/workspace-sync-metadata/workspace-sync.metadata.service'; @Module({ @@ -25,7 +26,7 @@ import { WorkspaceSyncMetadataService } from 'src/workspace/workspace-sync-metad ), TypeOrmModule.forFeature([FeatureFlagEntity], 'core'), ], + providers: [WorkspaceSyncMetadataService, ReflectiveMetadataFactory], exports: [WorkspaceSyncMetadataService], - providers: [WorkspaceSyncMetadataService], }) export class WorkspaceSyncMetadataModule {} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/workspace-sync.metadata.service.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/workspace-sync.metadata.service.ts index 0feecc1d5b..8ee869c39b 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/workspace-sync.metadata.service.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/workspace-sync.metadata.service.ts @@ -2,9 +2,16 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import diff from 'microdiff'; -import { Repository } from 'typeorm'; +import { In, Repository } from 'typeorm'; import camelCase from 'lodash.camelcase'; +import { PartialFieldMetadata } from 'src/workspace/workspace-sync-metadata/interfaces/partial-field-metadata.interface'; +import { PartialObjectMetadata } from 'src/workspace/workspace-sync-metadata/interfaces/partial-object-metadata.interface'; +import { + MappedFieldMetadataEntity, + MappedObjectMetadata, +} from 'src/workspace/workspace-sync-metadata/interfaces/mapped-metadata.interface'; + import { FieldMetadataEntity, FieldMetadataType, @@ -14,7 +21,6 @@ import { RelationMetadataEntity, RelationMetadataType, } from 'src/metadata/relation-metadata/relation-metadata.entity'; -import { MetadataParser } from 'src/workspace/workspace-sync-metadata/utils/metadata.parser'; import { filterIgnoredProperties, convertStringifiedFieldsToJSON, @@ -29,6 +35,7 @@ import { } from 'src/metadata/workspace-migration/workspace-migration.entity'; import { WorkspaceMigrationFactory } from 'src/metadata/workspace-migration/workspace-migration.factory'; import { WorkspaceMigrationRunnerService } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.service'; +import { ReflectiveMetadataFactory } from 'src/workspace/workspace-sync-metadata/reflective-metadata.factory'; import { FeatureFlagEntity } from 'src/core/feature-flag/feature-flag.entity'; @Injectable() @@ -36,6 +43,7 @@ export class WorkspaceSyncMetadataService { constructor( private readonly workspaceMigrationFactory: WorkspaceMigrationFactory, private readonly workspaceMigrationRunnerService: WorkspaceMigrationRunnerService, + private readonly reflectiveMetadataFactory: ReflectiveMetadataFactory, @InjectRepository(ObjectMetadataEntity, 'metadata') private readonly objectMetadataRepository: Repository, @@ -75,32 +83,37 @@ export class WorkspaceSyncMetadataService { {}, ); - const standardObjects = MetadataParser.parseAllMetadata( - standardObjectMetadata, - workspaceId, - dataSourceId, - workspaceFeatureFlagsMap, - ); + const standardObjects = + await this.reflectiveMetadataFactory.createObjectMetadataCollection( + standardObjectMetadata, + workspaceId, + dataSourceId, + workspaceFeatureFlagsMap, + ); const objectsInDB = await this.objectMetadataRepository.find({ - where: { workspaceId, dataSourceId, isCustom: false }, - relations: ['fields'], + where: { workspaceId, isCustom: false }, + relations: ['dataSource', 'fields'], }); - const objectsInDBByName = - mapObjectMetadataByUniqueIdentifier(objectsInDB); - const standardObjectsByName = - mapObjectMetadataByUniqueIdentifier(standardObjects); + const objectsInDBByName = mapObjectMetadataByUniqueIdentifier< + ObjectMetadataEntity, + FieldMetadataEntity + >(objectsInDB); + const standardObjectsByName = mapObjectMetadataByUniqueIdentifier< + PartialObjectMetadata, + PartialFieldMetadata + >(standardObjects); - const objectsToCreate: ObjectMetadataEntity[] = []; + const objectsToCreate: MappedObjectMetadata[] = []; const objectsToDelete = objectsInDB.filter( (objectInDB) => !standardObjectsByName[objectInDB.nameSingular], ); const objectsToUpdate: Record = {}; - const fieldsToCreate: FieldMetadataEntity[] = []; + const fieldsToCreate: PartialFieldMetadata[] = []; const fieldsToDelete: FieldMetadataEntity[] = []; - const fieldsToUpdate: Record = {}; + const fieldsToUpdate: Record = {}; for (const standardObjectName in standardObjectsByName) { const standardObject = standardObjectsByName[standardObjectName]; @@ -187,13 +200,15 @@ export class WorkspaceSyncMetadataService { for (const diff of fieldsDiff) { const fieldName = diff.path[0]; - if (diff.type === 'CREATE') + if (diff.type === 'CREATE') { fieldsToCreate.push({ ...standardObjectFields[fieldName], objectMetadataId: objectInDB.id, }); - if (diff.type === 'REMOVE' && diff.path.length === 1) + } + if (diff.type === 'REMOVE' && diff.path.length === 1) { fieldsToDelete.push(objectInDBFields[fieldName]); + } if (diff.type === 'CHANGE') { const property = diff.path[diff.path.length - 1]; @@ -206,16 +221,25 @@ export class WorkspaceSyncMetadataService { } // CREATE OBJECTS - await this.objectMetadataRepository.save( - objectsToCreate.map((object) => ({ - ...object, - isActive: true, - fields: Object.values(object.fields).map((field) => ({ - ...convertStringifiedFieldsToJSON(field), + const createdObjectMetadataCollection = + await this.objectMetadataRepository.save( + objectsToCreate.map((object) => ({ + ...object, isActive: true, + fields: Object.values(object.fields).map((field) => ({ + ...convertStringifiedFieldsToJSON(field), + isActive: true, + })), })), - })), + ); + const identifiers = createdObjectMetadataCollection.map( + (object) => object.id, ); + const createdObjects = await this.objectMetadataRepository.find({ + where: { id: In(identifiers) }, + relations: ['dataSource', 'fields'], + }); + // UPDATE OBJECTS, this is not optimal as we are running n queries here. for (const [key, value] of Object.entries(objectsToUpdate)) { await this.objectMetadataRepository.update(key, value); @@ -228,9 +252,10 @@ export class WorkspaceSyncMetadataService { } // CREATE FIELDS - await this.fieldMetadataRepository.save( + const createdFields = await this.fieldMetadataRepository.save( fieldsToCreate.map((field) => convertStringifiedFieldsToJSON(field)), ); + // UPDATE FIELDS for (const [key, value] of Object.entries(fieldsToUpdate)) { await this.fieldMetadataRepository.update( @@ -252,9 +277,9 @@ export class WorkspaceSyncMetadataService { // Generate migrations await this.generateMigrationsFromSync( - objectsToCreate, + createdObjects, objectsToDelete, - fieldsToCreate, + createdFields, fieldsToDelete, objectsInDB, ); @@ -282,16 +307,20 @@ export class WorkspaceSyncMetadataService { workspaceFeatureFlagsMap: Record, ) { const objectsInDB = await this.objectMetadataRepository.find({ - where: { workspaceId, dataSourceId, isCustom: false }, - relations: ['fields'], + where: { workspaceId, isCustom: false }, + relations: ['dataSource', 'fields'], }); - const objectsInDBByName = mapObjectMetadataByUniqueIdentifier(objectsInDB); - const standardRelations = MetadataParser.parseAllRelations( - standardObjectMetadata, - workspaceId, - objectsInDBByName, - workspaceFeatureFlagsMap, - ); + const objectsInDBByName = mapObjectMetadataByUniqueIdentifier< + ObjectMetadataEntity, + FieldMetadataEntity + >(objectsInDB); + const standardRelations = + this.reflectiveMetadataFactory.createRelationMetadataCollection( + standardObjectMetadata, + workspaceId, + objectsInDBByName, + workspaceFeatureFlagsMap, + ); // TODO: filter out custom relations once isCustom has been added to relationMetadata table const relationsInDB = await this.relationMetadataRepository.find({ @@ -364,6 +393,7 @@ export class WorkspaceSyncMetadataService { { name: object.targetTableName, action: 'create', + schemaName: object.dataSource.schema, } satisfies WorkspaceMigrationTableAction, ...Object.values(object.fields) .filter((field) => field.type !== FieldMetadataType.RELATION) @@ -372,6 +402,7 @@ export class WorkspaceSyncMetadataService { ({ name: object.targetTableName, action: 'alter', + schemaName: object.dataSource.schema, columns: this.workspaceMigrationFactory.createColumnActions( WorkspaceMigrationColumnActionType.CREATE, field, @@ -395,7 +426,7 @@ export class WorkspaceSyncMetadataService { result[currentObject.id] = currentObject; return result; - }, {}); + }, {} as Record); if (fieldsToCreate.length > 0) { fieldsToCreate.map((field) => { @@ -403,6 +434,8 @@ export class WorkspaceSyncMetadataService { { name: objectsInDbById[field.objectMetadataId].targetTableName, action: 'alter', + schemaName: + objectsInDbById[field.objectMetadataId].dataSource.schema, columns: this.workspaceMigrationFactory.createColumnActions( WorkspaceMigrationColumnActionType.CREATE, field, @@ -424,6 +457,8 @@ export class WorkspaceSyncMetadataService { { name: objectsInDbById[field.objectMetadataId].targetTableName, action: 'alter', + schemaName: + objectsInDbById[field.objectMetadataId].dataSource.schema, columns: [ { action: WorkspaceMigrationColumnActionType.DROP, @@ -489,11 +524,13 @@ export class WorkspaceSyncMetadataService { { name: toObjectMetadata.targetTableName, action: 'alter', + schemaName: toObjectMetadata.dataSource.schema, columns: [ { action: WorkspaceMigrationColumnActionType.RELATION, columnName: `${camelCase(toFieldMetadata.name)}Id`, referencedTableName: fromObjectMetadata.targetTableName, + referencedSchema: fromObjectMetadata.dataSource.schema, referencedTableColumnName: 'id', isUnique: relation.relationType === RelationMetadataType.ONE_TO_ONE,