Skip to content

Commit 001ffdc

Browse files
authored
Merge pull request #3 from GeneralMagicio/create-models
created initial models
2 parents 06e098a + 9e6aadc commit 001ffdc

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
postgres:
3+
image: postgres:latest
4+
container_name: postgres_db
5+
restart: always
6+
environment:
7+
- POSTGRES_DB=qv
8+
- POSTGRES_USER=postgres
9+
- POSTGRES_PASSWORD=postgres
10+
volumes:
11+
- postgres_data:/var/lib/postgresql/data
12+
13+
ports:
14+
- '5433:5432'
15+
16+
volumes:
17+
postgres_data:
18+
driver: local
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
-- CreateEnum
2+
CREATE TYPE "ActionType" AS ENUM ('CREATED', 'VOTED');
3+
4+
-- CreateTable
5+
CREATE TABLE "User" (
6+
"worldID" TEXT NOT NULL,
7+
"name" TEXT NOT NULL,
8+
"profilePicture" TEXT,
9+
"pollsCreatedCount" INTEGER NOT NULL DEFAULT 0,
10+
"pollsParticipatedCount" INTEGER NOT NULL DEFAULT 0,
11+
12+
CONSTRAINT "User_pkey" PRIMARY KEY ("worldID")
13+
);
14+
15+
-- CreateTable
16+
CREATE TABLE "UserAction" (
17+
"id" TEXT NOT NULL,
18+
"worldID" TEXT NOT NULL,
19+
"actionID" TEXT NOT NULL,
20+
"pollID" TEXT NOT NULL,
21+
"type" "ActionType" NOT NULL,
22+
23+
CONSTRAINT "UserAction_pkey" PRIMARY KEY ("id")
24+
);
25+
26+
-- CreateTable
27+
CREATE TABLE "Poll" (
28+
"pollID" TEXT NOT NULL,
29+
"authorUserID" TEXT NOT NULL,
30+
"title" TEXT NOT NULL,
31+
"description" TEXT,
32+
"options" TEXT[],
33+
"creationDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
34+
"startDate" TIMESTAMP(3) NOT NULL,
35+
"endDate" TIMESTAMP(3) NOT NULL,
36+
"tags" TEXT[],
37+
"isAnonymous" BOOLEAN NOT NULL DEFAULT false,
38+
"participantCount" INTEGER NOT NULL DEFAULT 0,
39+
"voteResults" JSONB NOT NULL,
40+
41+
CONSTRAINT "Poll_pkey" PRIMARY KEY ("pollID")
42+
);
43+
44+
-- CreateTable
45+
CREATE TABLE "Vote" (
46+
"voteID" TEXT NOT NULL,
47+
"worldID" TEXT NOT NULL,
48+
"pollID" TEXT NOT NULL,
49+
"votingPower" INTEGER NOT NULL,
50+
"weightDistribution" JSONB NOT NULL,
51+
"proof" TEXT NOT NULL,
52+
53+
CONSTRAINT "Vote_pkey" PRIMARY KEY ("voteID")
54+
);
55+
56+
-- CreateIndex
57+
CREATE UNIQUE INDEX "UserAction_actionID_key" ON "UserAction"("actionID");
58+
59+
-- AddForeignKey
60+
ALTER TABLE "UserAction" ADD CONSTRAINT "UserAction_worldID_fkey" FOREIGN KEY ("worldID") REFERENCES "User"("worldID") ON DELETE CASCADE ON UPDATE CASCADE;
61+
62+
-- AddForeignKey
63+
ALTER TABLE "Poll" ADD CONSTRAINT "Poll_authorUserID_fkey" FOREIGN KEY ("authorUserID") REFERENCES "User"("worldID") ON DELETE CASCADE ON UPDATE CASCADE;
64+
65+
-- AddForeignKey
66+
ALTER TABLE "Vote" ADD CONSTRAINT "Vote_worldID_fkey" FOREIGN KEY ("worldID") REFERENCES "User"("worldID") ON DELETE CASCADE ON UPDATE CASCADE;
67+
68+
-- AddForeignKey
69+
ALTER TABLE "Vote" ADD CONSTRAINT "Vote_pollID_fkey" FOREIGN KEY ("pollID") REFERENCES "Poll"("pollID") ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (e.g., Git)
3+
provider = "postgresql"

prisma/schema.prisma

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,57 @@ datasource db {
1212
provider = "postgresql"
1313
url = env("DATABASE_URL")
1414
}
15+
16+
17+
model User {
18+
worldID String @id
19+
name String
20+
profilePicture String?
21+
pollsCreatedCount Int @default(0)
22+
pollsParticipatedCount Int @default(0)
23+
createdPolls Poll[] @relation("PollAuthor")
24+
votes Vote[]
25+
actions UserAction[]
26+
}
27+
28+
model UserAction {
29+
id String @id @default(uuid())
30+
worldID String
31+
actionID String @unique
32+
pollID String
33+
type ActionType
34+
user User @relation(fields: [worldID], references: [worldID], onDelete: Cascade)
35+
}
36+
37+
model Poll {
38+
pollID String @id @default(uuid())
39+
authorUserID String
40+
title String
41+
description String?
42+
options String[]
43+
creationDate DateTime @default(now())
44+
startDate DateTime
45+
endDate DateTime
46+
tags String[]
47+
isAnonymous Boolean @default(false)
48+
participantCount Int @default(0)
49+
voteResults Json
50+
author User @relation("PollAuthor", fields: [authorUserID], references: [worldID], onDelete: Cascade)
51+
votes Vote[]
52+
}
53+
54+
model Vote {
55+
voteID String @id @default(uuid())
56+
worldID String
57+
pollID String
58+
votingPower Int
59+
weightDistribution Json
60+
proof String
61+
user User @relation(fields: [worldID], references: [worldID], onDelete: Cascade)
62+
poll Poll @relation(fields: [pollID], references: [pollID], onDelete: Cascade)
63+
}
64+
65+
enum ActionType {
66+
CREATED
67+
VOTED
68+
}

0 commit comments

Comments
 (0)