Migrate view field to new data model - Part 2 (#2270)

* Migrate view field to new data model

* Migrate view fields to new model
This commit is contained in:
Charles Bochet
2023-10-28 19:13:48 +02:00
committed by GitHub
parent b591023eb3
commit 685d342170
168 changed files with 960 additions and 4568 deletions

View File

@ -0,0 +1,52 @@
/*
Warnings:
- You are about to drop the column `index` on the `pipeline_stages` table. All the data in the column will be lost.
- You are about to drop the `viewFields` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `viewFilters` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `viewSorts` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `views` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "viewFields" DROP CONSTRAINT "viewFields_viewId_fkey";
-- DropForeignKey
ALTER TABLE "viewFields" DROP CONSTRAINT "viewFields_workspaceId_fkey";
-- DropForeignKey
ALTER TABLE "viewFilters" DROP CONSTRAINT "viewFilters_viewId_fkey";
-- DropForeignKey
ALTER TABLE "viewFilters" DROP CONSTRAINT "viewFilters_workspaceId_fkey";
-- DropForeignKey
ALTER TABLE "viewSorts" DROP CONSTRAINT "viewSorts_viewId_fkey";
-- DropForeignKey
ALTER TABLE "viewSorts" DROP CONSTRAINT "viewSorts_workspaceId_fkey";
-- DropForeignKey
ALTER TABLE "views" DROP CONSTRAINT "views_workspaceId_fkey";
-- AlterTable
ALTER TABLE "pipeline_stages" DROP COLUMN "index",
ADD COLUMN "position" INTEGER;
-- DropTable
DROP TABLE "viewFields";
-- DropTable
DROP TABLE "viewFilters";
-- DropTable
DROP TABLE "viewSorts";
-- DropTable
DROP TABLE "views";
-- DropEnum
DROP TYPE "ViewFilterOperand";
-- DropEnum
DROP TYPE "ViewSortDirection";

View File

@ -174,10 +174,6 @@ model Workspace {
pipelineStages PipelineStage[]
pipelineProgresses PipelineProgress[]
activityTargets ActivityTarget[]
viewFields ViewField[]
viewFilters ViewFilter[]
views View[]
viewSorts ViewSort[]
apiKeys ApiKey[]
webHooks WebHook[]
@ -657,19 +653,19 @@ model Pipeline {
model PipelineStage {
/// @Validator.IsString()
/// @Validator.IsOptional()
id String @id @default(uuid())
id String @id @default(uuid())
/// @Validator.IsString()
/// @Validator.IsOptional()
name String
name String
/// @Validator.IsString()
/// @Validator.IsOptional()
type String
type String
/// @Validator.IsOptional()
/// @Validator.IsString()
color String
color String
/// @Validator.IsNumber()
/// @Validator.IsOptional()
index Int?
position Int?
pipelineProgresses PipelineProgress[]
///
@ -799,97 +795,6 @@ enum ViewType {
Pipeline
}
model View {
/// @Validator.IsString()
/// @Validator.IsOptional()
id String @id @default(uuid())
fields ViewField[]
filters ViewFilter[]
name String
objectId String
sorts ViewSort[]
type ViewType
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
@@map("views")
}
enum ViewFilterOperand {
Contains
DoesNotContain
GreaterThan
LessThan
Is
IsNot
IsNotNull
}
model ViewFilter {
displayValue String
key String
name String
operand ViewFilterOperand
value String
view View @relation(fields: [viewId], references: [id], onDelete: Cascade)
viewId String
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
@@id([viewId, key])
@@map("viewFilters")
}
enum ViewSortDirection {
asc
desc
}
model ViewSort {
direction ViewSortDirection
key String
name String
view View @relation(fields: [viewId], references: [id], onDelete: Cascade)
viewId String
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
@@id([viewId, key])
@@map("viewSorts")
}
model ViewField {
index Float
isVisible Boolean
key String
name String
objectId String
size Int?
view View @relation(fields: [viewId], references: [id], onDelete: Cascade)
viewId String
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
@@id([viewId, key])
@@map("viewFields")
}
model ApiKey {
/// @Validator.IsString()
/// @Validator.IsOptional()
@ -913,17 +818,17 @@ model ApiKey {
model WebHook {
/// @Validator.IsString()
/// @Validator.IsOptional()
id String @id @default(uuid())
id String @id @default(uuid())
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
targetUrl String
operation String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
targetUrl String
operation String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
/// @TypeGraphQL.omit(input: true, output: true)
deletedAt DateTime?
deletedAt DateTime?
@@map("web_hooks")
}

View File

@ -6,7 +6,6 @@ import { seedPeople } from './people';
import { seedComments } from './comments';
import { seedUsers } from './users';
import { seedPipelines } from './pipelines';
import { seedViews } from './views';
import { seedMetadata } from './metadata';
const seed = async () => {
@ -17,7 +16,6 @@ const seed = async () => {
await seedPeople(prisma);
await seedComments(prisma);
await seedPipelines(prisma);
await seedViews(prisma);
await seedMetadata(prisma);
await prisma.$disconnect();
};

View File

@ -19,7 +19,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-fe256b39-3ec3-4fe3-8998-b76aa0bfb600',
name: 'New',
color: 'red',
index: 0,
position: 0,
type: 'open',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
@ -33,7 +33,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-fe256b39-3ec3-4fe4-8998-b76aa0bfb600',
name: 'Screening',
color: 'purple',
index: 1,
position: 1,
type: 'ongoing',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
@ -47,7 +47,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-fe256b39-3ec3-4fe5-8998-b76aa0bfb600',
name: 'Meeting',
color: 'sky',
index: 2,
position: 2,
type: 'ongoing',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
@ -61,7 +61,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-fe256b39-3ec3-4fe6-8998-b76aa0bfb600',
name: 'Proposal',
color: 'turquoise',
index: 3,
position: 3,
type: 'ongoing',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
@ -75,7 +75,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-fe256b39-3ec3-4fe7-8998-b76aa0bfb600',
name: 'Customer',
color: 'yellow',
index: 4,
position: 4,
type: 'won',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
@ -149,7 +149,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-fe256b39-3ec3-4fe3-8998-a76aa0bfb600',
name: 'New',
color: 'red',
index: 1,
position: 1,
type: 'open',
pipelineId: 'twenty-fe256b39-3ec3-4fe3-8997-b74aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
@ -186,7 +186,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-dev-fe256b39-3ec3-4fe3-8998-b76aa0bfb600',
name: 'New',
color: 'red',
index: 0,
position: 0,
type: 'open',
pipelineId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
@ -200,7 +200,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-dev-fe256b39-3ec3-4fe4-8998-b76aa0bfb600',
name: 'Screening',
color: 'purple',
index: 1,
position: 1,
type: 'ongoing',
pipelineId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
@ -214,7 +214,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-dev-fe256b39-3ec3-4fe5-8998-b76aa0bfb600',
name: 'Meeting',
color: 'sky',
index: 2,
position: 2,
type: 'ongoing',
pipelineId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
@ -228,7 +228,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-dev-fe256b39-3ec3-4fe6-8998-b76aa0bfb600',
name: 'Proposal',
color: 'turquoise',
index: 3,
position: 3,
type: 'ongoing',
pipelineId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
@ -242,7 +242,7 @@ export const seedPipelines = async (prisma: PrismaClient) => {
id: 'twenty-dev-fe256b39-3ec3-4fe7-8998-b76aa0bfb600',
name: 'Customer',
color: 'yellow',
index: 4,
position: 4,
type: 'won',
pipelineId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b75aa0bfb400',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',

View File

@ -1,201 +0,0 @@
import { PrismaClient } from '@prisma/client';
export const seedViews = async (prisma: PrismaClient) => {
const workspaceId = 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419';
const companyViewId = 'twenty-5e924b69-a619-41bf-bd31-a9e8551fc9d1';
const personViewId = 'twenty-db9e6c85-c091-4fd6-88b1-c1830f5e90d1';
const opportunitiesViewId = 'twenty-6abb47a2-7a91-4679-a538-59946f0c06a9';
await prisma.view.upsert({
where: { id: companyViewId },
update: {},
create: {
id: companyViewId,
name: 'All Companies',
objectId: 'company',
type: 'Table',
workspaceId,
},
});
await Promise.all(
[
{
key: 'name',
name: 'Name',
size: 180,
},
{
key: 'domainName',
name: 'URL',
size: 100,
},
{
key: 'accountOwner',
name: 'Account Owner',
size: 150,
},
{
key: 'createdAt',
name: 'Creation',
size: 150,
},
{
key: 'employees',
name: 'Employees',
size: 150,
},
{
key: 'linkedin',
name: 'LinkedIn',
size: 170,
},
{
key: 'address',
name: 'Address',
size: 170,
},
{
key: 'annualRecurringRevenue',
name: 'ARR',
size: 150,
},
].map((viewField, index) =>
prisma.viewField.upsert({
where: { viewId_key: { key: viewField.key, viewId: companyViewId } },
update: {},
create: {
...viewField,
index,
isVisible: true,
objectId: 'company',
viewId: companyViewId,
workspaceId,
},
}),
),
);
await prisma.view.upsert({
where: { id: personViewId },
update: {},
create: {
id: personViewId,
name: 'All People',
objectId: 'person',
type: 'Table',
workspaceId,
},
});
await Promise.all(
[
{
key: 'displayName',
name: 'People',
size: 210,
},
{
key: 'email',
name: 'Email',
size: 150,
},
{
key: 'company',
name: 'Company',
size: 150,
},
{
key: 'phone',
name: 'Phone',
size: 150,
},
{
key: 'createdAt',
name: 'Creation',
size: 150,
},
{
key: 'city',
name: 'City',
size: 150,
},
{
key: 'jobTitle',
name: 'Job title',
size: 150,
},
{
key: 'linkedin',
name: 'LinkedIn',
size: 150,
},
{
key: 'x',
name: 'Twitter',
size: 150,
},
].map((viewField, index) =>
prisma.viewField.upsert({
where: { viewId_key: { key: viewField.key, viewId: personViewId } },
update: {},
create: {
...viewField,
index,
isVisible: true,
objectId: 'person',
viewId: personViewId,
workspaceId,
},
}),
),
);
await prisma.view.upsert({
where: { id: opportunitiesViewId },
update: {},
create: {
id: opportunitiesViewId,
name: 'All Opportunities',
objectId: 'company',
type: 'Pipeline',
workspaceId,
},
});
await Promise.all(
[
{
key: 'closeDate',
name: 'Close Date',
},
{
key: 'amount',
name: 'Amount',
},
{
key: 'probability',
name: 'Probability',
},
{
key: 'pointOfContact',
name: 'Point of Contact',
},
].map((viewField, index) =>
prisma.viewField.upsert({
where: {
viewId_key: { key: viewField.key, viewId: opportunitiesViewId },
},
update: {},
create: {
...viewField,
index,
isVisible: true,
objectId: 'company',
viewId: opportunitiesViewId,
workspaceId,
},
}),
),
);
};