Add Pipelines models in server (#182)

* Hide workspace and refresh token from schema

* Add pipe models and migrations

* Add seeds

* Update FE graphql schema
This commit is contained in:
Charles Bochet
2023-06-02 11:20:21 +02:00
committed by GitHub
parent bf3097500a
commit 2395f791c8
335 changed files with 8371 additions and 428 deletions

View File

@ -0,0 +1,59 @@
-- CreateEnum
CREATE TYPE "PipelineAssociableType" AS ENUM ('Person', 'Company');
-- CreateTable
CREATE TABLE "pipelines" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"deletedAt" TIMESTAMP(3),
"name" TEXT NOT NULL,
"icon" TEXT NOT NULL,
"workspaceId" TEXT NOT NULL,
CONSTRAINT "pipelines_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "pipeline_stages" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"deletedAt" TIMESTAMP(3),
"name" TEXT NOT NULL,
"type" TEXT NOT NULL,
"color" TEXT NOT NULL,
"pipelineId" TEXT NOT NULL,
"workspaceId" TEXT NOT NULL,
CONSTRAINT "pipeline_stages_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "pipeline_associations" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"deletedAt" TIMESTAMP(3),
"pipelineId" TEXT NOT NULL,
"pipelineStageId" TEXT NOT NULL,
"associableType" "PipelineAssociableType" NOT NULL,
"associableId" TEXT NOT NULL,
CONSTRAINT "pipeline_associations_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "pipelines" ADD CONSTRAINT "pipelines_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "workspaces"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "pipeline_stages" ADD CONSTRAINT "pipeline_stages_pipelineId_fkey" FOREIGN KEY ("pipelineId") REFERENCES "pipelines"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "pipeline_stages" ADD CONSTRAINT "pipeline_stages_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "workspaces"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "pipeline_associations" ADD CONSTRAINT "pipeline_associations_pipelineId_fkey" FOREIGN KEY ("pipelineId") REFERENCES "pipelines"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "pipeline_associations" ADD CONSTRAINT "pipeline_associations_pipelineStageId_fkey" FOREIGN KEY ("pipelineStageId") REFERENCES "pipeline_stages"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -52,8 +52,10 @@ model User {
passwordHash String?
emailVerified Boolean @default(false)
metadata Json?
/// @TypeGraphQL.omit(input: true)
workspaceMember WorkspaceMember?
companies Company[]
/// @TypeGraphQL.omit(input: true, output: true)
refreshTokens RefreshToken[]
comments Comment[]
@ -74,6 +76,8 @@ model Workspace {
people Person[]
commentThreads CommentThread[]
comments Comment[]
pipelines Pipeline[]
pipelineStages PipelineStage[]
@@map("workspaces")
}
@ -85,9 +89,9 @@ model WorkspaceMember {
deletedAt DateTime?
userId String @unique
user User @relation(fields: [userId], references: [id])
/// @TypeGraphQL.omit(input: true)
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
/// @TypeGraphQL.omit(input: true)
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
@@map("workspace_members")
@ -106,9 +110,9 @@ model Company {
accountOwner User? @relation(fields: [accountOwnerId], references: [id])
people Person[]
/// @TypeGraphQL.omit(input: true)
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
/// @TypeGraphQL.omit(input: true)
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
@@map("companies")
@ -127,9 +131,9 @@ model Person {
companyId String?
company Company? @relation(fields: [companyId], references: [id])
/// @TypeGraphQL.omit(input: true)
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
/// @TypeGraphQL.omit(input: true)
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
@@map("people")
@ -154,9 +158,9 @@ model CommentThread {
deletedAt DateTime?
commentThreadTargets CommentThreadTarget[]
comments Comment[]
/// @TypeGraphQL.omit(input: true)
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
/// @TypeGraphQL.omit(input: true)
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
@@map("comment_threads")
@ -172,9 +176,9 @@ model Comment {
author User @relation(fields: [authorId], references: [id])
commentThreadId String
commentThread CommentThread @relation(fields: [commentThreadId], references: [id])
/// @TypeGraphQL.omit(input: true)
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
/// @TypeGraphQL.omit(input: true)
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
@@map("comments")
@ -197,4 +201,68 @@ model CommentThreadTarget {
commentableId String
@@map("comment_thread_targets")
}
}
model Pipeline {
id String @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
name String
icon String
pipelineStages PipelineStage[]
pipelineAssociations PipelineAssociation[]
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
@@map("pipelines")
}
model PipelineStage {
id String @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
name String
type String
color String
pipelineId String
pipeline Pipeline @relation(fields: [pipelineId], references: [id])
pipelineAssociations PipelineAssociation[]
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
@@map("pipeline_stages")
}
enum PipelineAssociableType {
Person
Company
}
model PipelineAssociation {
id String @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
pipelineId String
pipeline Pipeline @relation(fields: [pipelineId], references: [id])
pipelineStageId String
pipelineStage PipelineStage @relation(fields: [pipelineStageId], references: [id])
associableType PipelineAssociableType
associableId String
@@map("pipeline_associations")
}

View File

@ -4,6 +4,7 @@ import { seedWorkspaces } from './workspaces';
import { seedPeople } from './people';
import { seedComments } from './comments';
import { seedUsers } from './users';
import { seedPipelines } from './pipelines';
const seed = async () => {
const prisma = new PrismaClient();
@ -12,6 +13,7 @@ const seed = async () => {
await seedCompanies(prisma);
await seedPeople(prisma);
await seedComments(prisma);
await seedPipelines(prisma);
await prisma.$disconnect();
};

View File

@ -0,0 +1,214 @@
import { PrismaClient } from '@prisma/client';
export const seedPipelines = async (prisma: PrismaClient) => {
await prisma.pipeline.upsert({
where: { id: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400' },
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
name: 'Sales pipeline',
icon: '💰',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
await prisma.pipelineStage.upsert({
where: { id: 'twenty-fe256b39-3ec3-4fe3-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe3-8998-b76aa0bfb600',
name: 'New',
color: '#B76796',
type: 'open',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
await prisma.pipelineStage.upsert({
where: { id: 'twenty-fe256b39-3ec3-4fe4-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe4-8998-b76aa0bfb600',
name: 'Screening',
color: '#CB912F',
type: 'ongoing',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
await prisma.pipelineStage.upsert({
where: { id: 'twenty-fe256b39-3ec3-4fe5-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe5-8998-b76aa0bfb600',
name: 'Meeting',
color: '#9065B0',
type: 'ongoing',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
await prisma.pipelineStage.upsert({
where: { id: 'twenty-fe256b39-3ec3-4fe6-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe6-8998-b76aa0bfb600',
name: 'Proposal',
color: '#337EA9',
type: 'ongoing',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
await prisma.pipelineStage.upsert({
where: { id: 'twenty-fe256b39-3ec3-4fe7-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe7-8998-b76aa0bfb600',
name: 'Customer',
color: '#079039',
type: 'won',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
await prisma.pipelineAssociation.upsert({
where: { id: 'twenty-fe256b39-3ec3-4fe7-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe7-8998-b76aa0bfb600',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
pipelineStageId: 'twenty-fe256b39-3ec3-4fe3-8998-b76aa0bfb600',
associableType: 'Person',
associableId: 'twenty-755035db-623d-41fe-92e7-dd45b7c568e1',
},
});
await prisma.pipeline.upsert({
where: { id: 'twenty-fe256b39-3ec3-4fe3-8997-b74aa0bfb400' },
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe3-8997-b74aa0bfb400',
name: 'Customer support pipeline',
icon: '📔',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
await prisma.pipelineStage.upsert({
where: { id: 'twenty-fe256b39-3ec3-4fe3-8998-a76aa0bfb600' },
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe3-8998-a76aa0bfb600',
name: 'New',
color: '#B76796',
type: 'open',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b74aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
});
await prisma.pipelineAssociation.upsert({
where: { id: 'twenty-fe256b39-3ec3-4fe7-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe7-8998-b76aa0bfb600',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b74aa0bfb400',
pipelineStageId: 'twenty-fe256b39-3ec3-4fe3-8998-a76aa0bfb600',
associableType: 'Person',
associableId: 'twenty-755035db-623d-41fe-92e7-dd45b7c568e1',
},
});
await prisma.pipeline.upsert({
where: { id: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400' },
update: {},
create: {
id: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
name: 'Sales pipeline',
icon: '💰',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
},
});
await prisma.pipelineStage.upsert({
where: { id: 'twenty-dev-fe256b39-3ec3-4fe3-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-dev-fe256b39-3ec3-4fe3-8998-b76aa0bfb600',
name: 'New',
color: '#B76796',
type: 'open',
pipelineId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
},
});
await prisma.pipelineStage.upsert({
where: { id: 'twenty-dev-fe256b39-3ec3-4fe4-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-dev-fe256b39-3ec3-4fe4-8998-b76aa0bfb600',
name: 'Screening',
color: '#CB912F',
type: 'ongoing',
pipelineId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
},
});
await prisma.pipelineStage.upsert({
where: { id: 'twenty-dev-fe256b39-3ec3-4fe5-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-dev-fe256b39-3ec3-4fe5-8998-b76aa0bfb600',
name: 'Meeting',
color: '#9065B0',
type: 'ongoing',
pipelineId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
},
});
await prisma.pipelineStage.upsert({
where: { id: 'twenty-dev-fe256b39-3ec3-4fe6-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-dev-fe256b39-3ec3-4fe6-8998-b76aa0bfb600',
name: 'Proposal',
color: '#337EA9',
type: 'ongoing',
pipelineId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
},
});
await prisma.pipelineStage.upsert({
where: { id: 'twenty-dev-fe256b39-3ec3-4fe7-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-dev-fe256b39-3ec3-4fe7-8998-b76aa0bfb600',
name: 'Customer',
color: '#079039',
type: 'won',
pipelineId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
},
});
await prisma.pipelineAssociation.upsert({
where: { id: 'twenty-dev-fe256b39-3ec3-4fe7-8998-b76aa0bfb600' },
update: {},
create: {
id: 'twenty-dev-fe256b39-3ec3-4fe7-8998-b76aa0bfb600',
pipelineId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
pipelineStageId: 'twenty-dev-fe256b39-3ec3-4fe3-8998-b76aa0bfb600',
associableType: 'Company',
associableId: 'twenty-dev-a674fa6c-1455-4c57-afaf-dd5dc086361e',
},
});
};