feat: add views and viewSorts tables (#1131)

* feat: add views table

Closes #1120

* feat: add viewSorts table

Closes #1120
This commit is contained in:
Thaïs
2023-08-10 18:14:28 +02:00
committed by GitHub
parent 428acf4a13
commit 0f364cc9e7
8 changed files with 304 additions and 2 deletions

View File

@ -0,0 +1,40 @@
/*
Warnings:
- A unique constraint covering the columns `[workspaceId,viewId,objectName,fieldName]` on the table `viewFields` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateEnum
CREATE TYPE "ViewType" AS ENUM ('Table', 'Pipeline');
-- AlterTable
ALTER TABLE "viewFields" ADD COLUMN "viewId" TEXT;
-- CreateTable
CREATE TABLE "views" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"objectId" TEXT NOT NULL,
"type" "ViewType" NOT NULL,
"workspaceId" TEXT NOT NULL,
CONSTRAINT "views_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "views_workspaceId_type_objectId_name_key" ON "views"("workspaceId", "type", "objectId", "name");
-- CreateIndex
CREATE UNIQUE INDEX "viewFields_workspaceId_viewId_objectName_fieldName_key" ON "viewFields"("workspaceId", "viewId", "objectName", "fieldName");
-- 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;
-- AddForeignKey
ALTER TABLE "views" ADD CONSTRAINT "views_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "workspaces"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "viewFields" ADD CONSTRAINT "viewFields_viewId_fkey" FOREIGN KEY ("viewId") REFERENCES "views"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -0,0 +1,19 @@
-- CreateEnum
CREATE TYPE "ViewSortDirection" AS ENUM ('asc', 'desc');
-- CreateTable
CREATE TABLE "viewSorts" (
"direction" "ViewSortDirection" NOT NULL,
"key" TEXT NOT NULL,
"name" TEXT NOT NULL,
"viewId" TEXT NOT NULL,
"workspaceId" TEXT NOT NULL,
CONSTRAINT "viewSorts_pkey" PRIMARY KEY ("viewId","key")
);
-- AddForeignKey
ALTER TABLE "viewSorts" ADD CONSTRAINT "viewSorts_viewId_fkey" FOREIGN KEY ("viewId") REFERENCES "views"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "viewSorts" ADD CONSTRAINT "viewSorts_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "workspaces"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -174,6 +174,8 @@ model Workspace {
pipelineProgresses PipelineProgress[]
activityTargets ActivityTarget[]
viewFields ViewField[]
views View[]
viewSorts ViewSort[]
/// @TypeGraphQL.omit(input: true, output: true)
deletedAt DateTime?
@ -266,7 +268,7 @@ model Person {
linkedinUrl String?
/// @Validator.IsString()
/// @Validator.IsOptional()
xUrl String?
xUrl String?
/// @Validator.IsString()
/// @Validator.IsOptional()
jobTitle String?
@ -557,6 +559,53 @@ model Attachment {
@@map("attachments")
}
enum ViewType {
Table
Pipeline
}
model View {
/// @Validator.IsString()
/// @Validator.IsOptional()
id String @id @default(uuid())
fields ViewField[]
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
@@unique([workspaceId, type, objectId, name])
@@map("views")
}
enum ViewSortDirection {
asc
desc
}
model ViewSort {
direction ViewSortDirection
key String
name String
view View @relation(fields: [viewId], references: [id])
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 {
/// @Validator.IsString()
/// @Validator.IsOptional()
@ -568,10 +617,14 @@ model ViewField {
objectName String
sizeInPx Int
view View? @relation(fields: [viewId], references: [id])
viewId String?
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
@@unique([workspaceId, viewId, objectName, fieldName])
@@map("viewFields")
}