Migrate standard objects (#2439)
* Migrate standard objects * Add migrations * fix relation * fix: register RelationMetadataType enum * fix: correctly fix null relation --------- Co-authored-by: corentin <corentin@twenty.com> Co-authored-by: Jérémy Magrin <jeremy.magrin@gmail.com>
This commit is contained in:
@ -17,13 +17,14 @@ import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metada
|
||||
import { RelationMetadataEntity } from 'src/metadata/relation-metadata/relation-metadata.entity';
|
||||
|
||||
export enum FieldMetadataType {
|
||||
UUID = 'uuid',
|
||||
UUID = 'UUID',
|
||||
TEXT = 'TEXT',
|
||||
PHONE = 'PHONE',
|
||||
EMAIL = 'EMAIL',
|
||||
DATE = 'DATE',
|
||||
BOOLEAN = 'BOOLEAN',
|
||||
NUMBER = 'NUMBER',
|
||||
PROBABILITY = 'PROBABILITY',
|
||||
ENUM = 'ENUM',
|
||||
URL = 'URL',
|
||||
MONEY = 'MONEY',
|
||||
|
||||
@ -28,6 +28,7 @@ export function generateTargetColumnMap(
|
||||
case FieldMetadataType.PHONE:
|
||||
case FieldMetadataType.EMAIL:
|
||||
case FieldMetadataType.NUMBER:
|
||||
case FieldMetadataType.PROBABILITY:
|
||||
case FieldMetadataType.BOOLEAN:
|
||||
case FieldMetadataType.DATE:
|
||||
return {
|
||||
@ -70,11 +71,12 @@ export function convertFieldMetadataToColumnActions(
|
||||
},
|
||||
];
|
||||
case FieldMetadataType.NUMBER:
|
||||
case FieldMetadataType.PROBABILITY:
|
||||
return [
|
||||
{
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
columnName: fieldMetadata.targetColumnMap.value,
|
||||
columnType: 'integer',
|
||||
columnType: 'float',
|
||||
},
|
||||
];
|
||||
case FieldMetadataType.BOOLEAN:
|
||||
|
||||
@ -86,6 +86,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
'fields.fromRelationMetadata.toObjectMetadata.fields',
|
||||
'fields.toRelationMetadata',
|
||||
'fields.toRelationMetadata.fromObjectMetadata',
|
||||
'fields.toRelationMetadata.fromObjectMetadata.fields',
|
||||
'fields.toRelationMetadata.toObjectMetadata',
|
||||
],
|
||||
});
|
||||
@ -102,6 +103,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
'fields.fromRelationMetadata.toObjectMetadata.fields',
|
||||
'fields.toRelationMetadata',
|
||||
'fields.toRelationMetadata.fromObjectMetadata',
|
||||
'fields.toRelationMetadata.fromObjectMetadata.fields',
|
||||
'fields.toRelationMetadata.toObjectMetadata',
|
||||
],
|
||||
});
|
||||
|
||||
@ -17,7 +17,7 @@ import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-me
|
||||
export class CreateRelationInput {
|
||||
@IsEnum(RelationMetadataType)
|
||||
@IsNotEmpty()
|
||||
@Field()
|
||||
@Field(() => RelationMetadataType)
|
||||
relationType: RelationMetadataType;
|
||||
|
||||
@IsUUID()
|
||||
|
||||
@ -29,7 +29,7 @@ export class RelationMetadataDTO {
|
||||
@IDField(() => ID)
|
||||
id: string;
|
||||
|
||||
@Field()
|
||||
@Field(() => RelationMetadataType)
|
||||
relationType: RelationMetadataType;
|
||||
|
||||
@Field()
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { registerEnumType } from '@nestjs/graphql';
|
||||
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
@ -20,6 +22,11 @@ export enum RelationMetadataType {
|
||||
MANY_TO_MANY = 'MANY_TO_MANY',
|
||||
}
|
||||
|
||||
registerEnumType(RelationMetadataType, {
|
||||
name: 'RelationMetadataType',
|
||||
description: 'Type of the relation',
|
||||
});
|
||||
|
||||
@Entity('relationMetadata')
|
||||
export class RelationMetadataEntity implements RelationMetadataInterface {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
|
||||
@ -32,6 +32,42 @@ export const addCompanyTable: TenantMigrationTableAction[] = [
|
||||
columnType: 'integer',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'linkedinUrl_link',
|
||||
columnType: 'varchar',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'linkedinUrl',
|
||||
columnType: 'varchar',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'xUrl',
|
||||
columnType: 'varchar',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'annualRecurringRevenue',
|
||||
columnType: 'float',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'idealCustomerProfile',
|
||||
columnType: 'boolean',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'accountOwnerId',
|
||||
columnType: 'uuid',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'accountOwnerId',
|
||||
referencedTableName: 'workspaceMember',
|
||||
referencedTableColumnName: 'id',
|
||||
action: TenantMigrationColumnActionType.RELATION,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@ -17,11 +17,6 @@ export const addViewFilterTable: TenantMigrationTableAction[] = [
|
||||
columnType: 'varchar',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'viewId',
|
||||
columnType: 'varchar',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'operand',
|
||||
columnType: 'varchar',
|
||||
@ -37,6 +32,17 @@ export const addViewFilterTable: TenantMigrationTableAction[] = [
|
||||
columnType: 'varchar',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'viewId',
|
||||
columnType: 'uuid',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'viewId',
|
||||
referencedTableName: 'view',
|
||||
referencedTableColumnName: 'id',
|
||||
action: TenantMigrationColumnActionType.RELATION,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@ -17,16 +17,22 @@ export const addViewSortTable: TenantMigrationTableAction[] = [
|
||||
columnType: 'varchar',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'viewId',
|
||||
columnType: 'varchar',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'direction',
|
||||
columnType: 'varchar',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'viewId',
|
||||
columnType: 'uuid',
|
||||
action: TenantMigrationColumnActionType.CREATE,
|
||||
},
|
||||
{
|
||||
columnName: 'viewId',
|
||||
referencedTableName: 'view',
|
||||
referencedTableColumnName: 'id',
|
||||
action: TenantMigrationColumnActionType.RELATION,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addActivityTargetTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'activityTarget',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'activityTarget',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addActivityTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'activity',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'activity',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addApiKeyTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'apiKey',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'apiKey',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addAttachmentTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'attachment',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'attachment',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addCommentTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'comment',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'comment',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addFavoriteTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'favorite',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'favorite',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addOpportunityTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'opportunity',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'opportunity',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addPersonTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'person',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'person',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addPipelineStepTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'pipelineStep',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'pipelineStep',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addWebhookTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'webhook',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'webhook',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addWorkspaceMemberSettingTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'workspaceMemberSetting',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'workspaceMemberSetting',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -0,0 +1,13 @@
|
||||
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
|
||||
|
||||
export const addWorkspaceMemberTable: TenantMigrationTableAction[] = [
|
||||
{
|
||||
name: 'workspaceMember',
|
||||
action: 'create',
|
||||
},
|
||||
{
|
||||
name: 'workspaceMember',
|
||||
action: 'alter',
|
||||
columns: [],
|
||||
},
|
||||
];
|
||||
@ -1,3 +1,16 @@
|
||||
import { addActivityTargetTable } from 'src/metadata/tenant-migration/migrations/1697618015-addActivityTargetTable';
|
||||
import { addActivityTable } from 'src/metadata/tenant-migration/migrations/1697618016-addActivityTable';
|
||||
import { addApiKeyTable } from 'src/metadata/tenant-migration/migrations/1697618017-addApiKeyTable';
|
||||
import { addAttachmentTable } from 'src/metadata/tenant-migration/migrations/1697618018-addAttachmentTable';
|
||||
import { addCommentTable } from 'src/metadata/tenant-migration/migrations/1697618019-addCommentTable';
|
||||
import { addFavoriteTable } from 'src/metadata/tenant-migration/migrations/1697618020-addFavoriteTable';
|
||||
import { addOpportunityTable } from 'src/metadata/tenant-migration/migrations/1697618021-addOpportunityTable';
|
||||
import { addPersonTable } from 'src/metadata/tenant-migration/migrations/1697618022-addPersonTable';
|
||||
import { addPipelineStepTable } from 'src/metadata/tenant-migration/migrations/1697618023-addPipelineStepTable';
|
||||
import { addWebhookTable } from 'src/metadata/tenant-migration/migrations/1697618024-addWebhookTable';
|
||||
import { addWorkspaceMemberSettingTable } from 'src/metadata/tenant-migration/migrations/1697618025-addWorkspaceMemberSettingTable';
|
||||
import { addWorkspaceMemberTable } from 'src/metadata/tenant-migration/migrations/1697618026-addWorspaceMemberTable';
|
||||
|
||||
import { addCompanyTable } from './migrations/1697618009-addCompanyTable';
|
||||
import { addViewTable } from './migrations/1697618011-addViewTable';
|
||||
import { addViewFieldTable } from './migrations/1697618012-addViewFieldTable';
|
||||
@ -6,9 +19,22 @@ import { addViewSortTable } from './migrations/1697618014-addViewSortTable';
|
||||
|
||||
// TODO: read the folder and return all migrations
|
||||
export const standardMigrations = {
|
||||
'1697618009-addCompanyTable': addCompanyTable,
|
||||
'1697618011-addViewTable': addViewTable,
|
||||
'1697618012-addViewFieldTable': addViewFieldTable,
|
||||
'1697618013-addViewFilterTable': addViewFilterTable,
|
||||
'1697618014-addViewSortTable': addViewSortTable,
|
||||
|
||||
'1697618015-addActivityTargetTable': addActivityTargetTable,
|
||||
'1697618016-addActivityTable': addActivityTable,
|
||||
'1697618017-addApiKeyTable': addApiKeyTable,
|
||||
'1697618018-addAttachmentTable': addAttachmentTable,
|
||||
'1697618019-addCommentTable': addCommentTable,
|
||||
'1697618020-addFavoriteTable': addFavoriteTable,
|
||||
'1697618021-addOpportunityTable': addOpportunityTable,
|
||||
'1697618022-addPersonTable': addPersonTable,
|
||||
'1697618023-addPipelineStepTable': addPipelineStepTable,
|
||||
'1697618024-addWebhookTable': addWebhookTable,
|
||||
'1697618025-addWorkspaceMemberSettingTable': addWorkspaceMemberSettingTable,
|
||||
'1697618026-addWorkspaceMemberTable': addWorkspaceMemberTable,
|
||||
'1697618009-addCompanyTable': addCompanyTable,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user