Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal blocks schema #105

Merged
merged 10 commits into from
Aug 31, 2023
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@charmverse/core",
"version": "0.3.10",
"version": "0.3.11-rc-feat-proposal-c.0",
"description": "Core API for Charmverse",
"type": "commonjs",
"types": "./dist/cjs/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/lib/testing/__tests__/proposals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ describe('generateProposal', () => {
roleId: role.id,
userId: null
}
]
],
fields: null
});

const proposalPageFromDb = (await prisma.page.findUnique({
Expand Down
39 changes: 39 additions & 0 deletions src/prisma/migrations/20230828212153_proposal_blocks/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- CreateEnum
CREATE TYPE "ProposalBlockType" AS ENUM ('properties', 'view');

-- AlterTable
ALTER TABLE "Proposal" ADD COLUMN "fields" JSONB;

-- CreateTable
CREATE TABLE "ProposalBlock" (
"id" UUID NOT NULL,
"deletedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"createdBy" UUID NOT NULL,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedBy" UUID NOT NULL,
"spaceId" UUID NOT NULL,
"parentId" TEXT NOT NULL,
"rootId" UUID NOT NULL,
"schema" INTEGER NOT NULL,
"type" "ProposalBlockType" NOT NULL,
"title" TEXT NOT NULL,
"fields" JSONB NOT NULL,

CONSTRAINT "ProposalBlock_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "ProposalBlock_rootId_idx" ON "ProposalBlock"("rootId");

-- CreateIndex
CREATE INDEX "ProposalBlock_spaceId_idx" ON "ProposalBlock"("spaceId");

-- CreateIndex
CREATE INDEX "ProposalBlock_createdBy_idx" ON "ProposalBlock"("createdBy");

-- AddForeignKey
ALTER TABLE "ProposalBlock" ADD CONSTRAINT "ProposalBlock_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ProposalBlock" ADD CONSTRAINT "ProposalBlock_spaceId_fkey" FOREIGN KEY ("spaceId") REFERENCES "Space"("id") ON DELETE CASCADE ON UPDATE CASCADE;
30 changes: 30 additions & 0 deletions src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ model Space {
postTags PostTag[]
blockCounts BlockCount[]
blockQuota Int @default(0)
ProposalBlock ProposalBlock[]

@@index([createdBy])
}
Expand Down Expand Up @@ -618,6 +619,7 @@ model User {
verifiedEmails VerifiedEmail[]
apiPageKeys ApiPageKey[]
spaceActions UserSpaceAction[]
ProposalBlock ProposalBlock[]
}

model VerifiedEmail {
Expand Down Expand Up @@ -1113,12 +1115,40 @@ model Proposal {
evaluationType ProposalEvaluationType @default(vote)
rubricCriteria ProposalRubricCriteria[]
rubricAnswers ProposalRubricCriteriaAnswer[]
fields Json?

@@index([spaceId])
@@index([reviewedBy])
@@index([categoryId])
}

enum ProposalBlockType {
properties
view
}

model ProposalBlock {
id String @id @db.Uuid
deletedAt DateTime?
createdAt DateTime @default(now())
createdBy String @db.Uuid
updatedAt DateTime @default(now())
updatedBy String @db.Uuid
spaceId String @db.Uuid
parentId String
rootId String @db.Uuid
schema Int
type ProposalBlockType
title String
fields Json
user User @relation(fields: [createdBy], references: [id])
space Space @relation(fields: [spaceId], references: [id], onDelete: Cascade)

@@index([rootId])
@@index([spaceId])
@@index([createdBy])
}

model ProposalAuthor {
proposalId String @db.Uuid
proposal Proposal @relation(fields: [proposalId], references: [id], onDelete: Cascade)
Expand Down