Refactor: Morph strategy on PipelineProgress (#1065)

* Deprecate pipelineprogress backref on person to improve naming

* Remove deprecated point of contact fields

* Add company and person entities on pipelineprogress

* Migrate data from old progressable to new entity fields

* Codegen frontend

* Use company Id, deprecate progressableId

* Get rid of deprecated progressableId field

* Remove deprecated progressableType field from pipeline progress

* Remove useless migrations
This commit is contained in:
Emilien Chauvet
2023-08-03 18:08:35 +02:00
committed by GitHub
parent 4252a0a2c3
commit 21e3d8fcac
15 changed files with 327 additions and 263 deletions

View File

@ -0,0 +1,9 @@
-- AlterTable
ALTER TABLE "pipeline_progresses" ADD COLUMN "companyId" TEXT,
ADD COLUMN "personId" TEXT;
-- AddForeignKey
ALTER TABLE "pipeline_progresses" ADD CONSTRAINT "pipeline_progresses_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "pipeline_progresses" ADD CONSTRAINT "pipeline_progresses_personId_fkey" FOREIGN KEY ("personId") REFERENCES "people"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -0,0 +1,8 @@
-- This is a manually written data migration that copies the progressable ids to the right colums in pipeline progress.
UPDATE "pipeline_progresses" SET
"companyId"="progressableId"
WHERE "progressableType"='Company';
UPDATE "pipeline_progresses" SET
"personId"="progressableId"
WHERE "progressableType"='Person';

View File

@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `progressableId` on the `pipeline_progresses` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "pipeline_progresses" DROP COLUMN "progressableId";

View File

@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `progressableType` on the `pipeline_progresses` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "pipeline_progresses" DROP COLUMN "progressableType";

View File

@ -240,9 +240,10 @@ model Company {
/// @TypeGraphQL.omit(input: true, output: true)
deletedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ActivityTarget ActivityTarget[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ActivityTarget ActivityTarget[]
PipelineProgress PipelineProgress[]
@@map("companies")
}
@ -276,20 +277,21 @@ model Person {
/// @Validator.IsOptional()
avatarUrl String?
company Company? @relation(fields: [companyId], references: [id])
companyId String?
company Company? @relation(fields: [companyId], references: [id])
companyId String?
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspace Workspace @relation(fields: [workspaceId], references: [id])
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
pipelineProgresses PipelineProgress[]
workspaceId String
contactPipelineProgresses PipelineProgress[] @relation("PointOfContactPipelineProgress")
/// @TypeGraphQL.omit(input: true, output: true)
deletedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ActivityTarget ActivityTarget[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ActivityTarget ActivityTarget[]
PipelineProgress PipelineProgress[]
@@map("people")
}
@ -488,18 +490,17 @@ model PipelineProgress {
closeDate DateTime?
probability Int?
pipeline Pipeline @relation(fields: [pipelineId], references: [id])
pipeline Pipeline @relation(fields: [pipelineId], references: [id])
pipelineId String
pipelineStage PipelineStage @relation(fields: [pipelineStageId], references: [id])
pipelineStage PipelineStage @relation(fields: [pipelineStageId], references: [id])
pipelineStageId String
pointOfContact Person? @relation(fields: [pointOfContactId], references: [id])
pointOfContact Person? @relation("PointOfContactPipelineProgress", fields: [pointOfContactId], references: [id])
pointOfContactId String?
progressableType PipelineProgressableType
progressableId String
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspace Workspace @relation(fields: [workspaceId], references: [id])
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
workspaceId String
/// @TypeGraphQL.omit(input: true, output: true)
deletedAt DateTime?
@ -507,6 +508,12 @@ model PipelineProgress {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
companyId String?
company Company? @relation(fields: [companyId], references: [id])
personId String?
person Person? @relation(fields: [personId], references: [id])
@@map("pipeline_progresses")
}

View File

@ -89,8 +89,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-fe256b39-3ec3-4fe7-8998-b76aa0bfb600',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
pipelineStageId: 'twenty-fe256b39-3ec3-4fe3-8998-b76aa0bfb600',
progressableType: 'Company',
progressableId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfa408',
companyId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfa408',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
@ -102,8 +101,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-4a886c90-f4f2-4984-8222-882ebbb905d6',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
pipelineStageId: 'twenty-fe256b39-3ec3-4fe4-8998-b76aa0bfb600',
progressableType: 'Company',
progressableId: 'twenty-118995f3-5d81-46d6-bf83-f7fd33ea6102',
companyId: 'twenty-118995f3-5d81-46d6-bf83-f7fd33ea6102',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
@ -115,8 +113,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-af92f3eb-d51d-4528-9b97-b8f132865b00',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
pipelineStageId: 'twenty-fe256b39-3ec3-4fe5-8998-b76aa0bfb600',
progressableType: 'Company',
progressableId: 'twenty-04b2e9f5-0713-40a5-8216-82802401d33e',
companyId: 'twenty-04b2e9f5-0713-40a5-8216-82802401d33e',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
@ -128,8 +125,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-08369b1a-acdb-43d6-95f9-67ac7436941a',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
pipelineStageId: 'twenty-fe256b39-3ec3-4fe5-8998-b76aa0bfb600',
progressableType: 'Company',
progressableId: 'twenty-460b6fb1-ed89-413a-b31a-962986e67bb4',
companyId: 'twenty-460b6fb1-ed89-413a-b31a-962986e67bb4',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
@ -167,8 +163,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-fe256b39-3ec3-4fe7-8998-b76aa0bfb600',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b74aa0bfb400',
pipelineStageId: 'twenty-fe256b39-3ec3-4fe3-8998-a76aa0bfb600',
progressableType: 'Person',
progressableId: 'twenty-755035db-623d-41fe-92e7-dd45b7c568e1',
personId: 'twenty-755035db-623d-41fe-92e7-dd45b7c568e1',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
@ -181,7 +176,6 @@ export const seedPipelines = async (prisma: PrismaClient) => {
name: 'Sales pipeline',
icon: '💰',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
pipelineProgressableType: 'Person',
},
});