diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..1eb1395 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +DATABASE_URL= + +MYSQL_DATABASE= +MYSQL_ROOT_PASSWORD= \ No newline at end of file diff --git a/package.json b/package.json index b104de5..550b75f 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@nestjs/common": "^11.0.1", "@nestjs/core": "^11.0.1", "@nestjs/platform-express": "^11.0.1", + "@prisma/client": "^6.3.1", "prisma": "^6.3.1", "reflect-metadata": "^0.2.2", "rxjs": "^7.8.1" diff --git a/prisma/migrations/20250205172850_/migration.sql b/prisma/migrations/20250205172850_/migration.sql new file mode 100644 index 0000000..188c572 --- /dev/null +++ b/prisma/migrations/20250205172850_/migration.sql @@ -0,0 +1,16 @@ +-- CreateTable +CREATE TABLE "User" ( + "id" SERIAL NOT NULL, + "worldId" TEXT NOT NULL, + "username" TEXT NOT NULL, + "name" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_worldId_key" ON "User"("worldId"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); diff --git a/prisma/migrations/20250205180025_user_entity/migration.sql b/prisma/migrations/20250205180025_user_entity/migration.sql new file mode 100644 index 0000000..7c36730 --- /dev/null +++ b/prisma/migrations/20250205180025_user_entity/migration.sql @@ -0,0 +1,10 @@ +/* + Warnings: + + - You are about to drop the column `name` on the `User` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "User" DROP COLUMN "name", +ADD COLUMN "pollsCreatedCount" INTEGER NOT NULL DEFAULT 0, +ADD COLUMN "profilePicture" TEXT; diff --git a/prisma/migrations/20250205193050_initail_entities/migration.sql b/prisma/migrations/20250205193050_initail_entities/migration.sql new file mode 100644 index 0000000..a3a7399 --- /dev/null +++ b/prisma/migrations/20250205193050_initail_entities/migration.sql @@ -0,0 +1,68 @@ +-- CreateTable +CREATE TABLE "Poll" ( + "id" SERIAL NOT NULL, + "userId" INTEGER NOT NULL, + "title" TEXT NOT NULL, + "description" TEXT, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "startDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "endDate" TIMESTAMP(3) NOT NULL, + "isAnonymous" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "Poll_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Option" ( + "id" SERIAL NOT NULL, + "optionText" TEXT NOT NULL, + "pollId" INTEGER NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Option_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Tag" ( + "id" SERIAL NOT NULL, + "content" TEXT, + + CONSTRAINT "Tag_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Vote" ( + "id" SERIAL NOT NULL, + "weight" INTEGER NOT NULL, + "optionId" INTEGER NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "proof" TEXT[], + + CONSTRAINT "Vote_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "_PollToTag" ( + "A" INTEGER NOT NULL, + "B" INTEGER NOT NULL, + + CONSTRAINT "_PollToTag_AB_pkey" PRIMARY KEY ("A","B") +); + +-- CreateIndex +CREATE INDEX "_PollToTag_B_index" ON "_PollToTag"("B"); + +-- AddForeignKey +ALTER TABLE "Poll" ADD CONSTRAINT "Poll_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Option" ADD CONSTRAINT "Option_pollId_fkey" FOREIGN KEY ("pollId") REFERENCES "Poll"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Vote" ADD CONSTRAINT "Vote_optionId_fkey" FOREIGN KEY ("optionId") REFERENCES "Option"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_PollToTag" ADD CONSTRAINT "_PollToTag_A_fkey" FOREIGN KEY ("A") REFERENCES "Poll"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_PollToTag" ADD CONSTRAINT "_PollToTag_B_fkey" FOREIGN KEY ("B") REFERENCES "Tag"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..648c57f --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (e.g., Git) +provider = "postgresql" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ee282c7..0cdae82 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -12,3 +12,56 @@ datasource db { provider = "postgresql" url = env("DATABASE_URL") } + +model User{ + id Int @id @default(autoincrement()) + worldId String @unique() + username String @unique() + profilePicture String? + pollsCreatedCount Int @default(0) + createdAt DateTime @default(now()) + poll Poll[] + +} + + +model Poll{ + id Int @id @default(autoincrement()) + user User @relation(fields: [userId],references: [id]) + userId Int + title String + description String? + options Option[] + tags Tag[] + createdAt DateTime @default(now()) + startDate DateTime @default(now()) + endDate DateTime + isAnonymous Boolean @default(false) + +} + +model Option { + id Int @id @default(autoincrement()) + optionText String + poll Poll @relation(fields: [pollId], references: [id]) + pollId Int + votes Vote[] + createdAt DateTime @default(now()) +} + +model Tag{ + id Int @id @default(autoincrement()) + content String? + poll Poll[] + +} + + +model Vote{ + id Int @id @default(autoincrement()) + weight Int + option Option @relation(fields: [optionId], references: [id]) + optionId Int + createdAt DateTime @default(now()) + proof String[] +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index e1d15fc..24ccefa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1063,6 +1063,11 @@ resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.1.1.tgz#1ec17e2edbec25c8306d424ecfbf13c7de1aaa31" integrity sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA== +"@prisma/client@^6.3.1": + version "6.3.1" + resolved "https://registry.yarnpkg.com/@prisma/client/-/client-6.3.1.tgz#4e4b05b27f4541ea541a601c57a8ada10b526848" + integrity sha512-ARAJaPs+eBkemdky/XU3cvGRl+mIPHCN2lCXsl5Vlb0E2gV+R6IN7aCI8CisRGszEZondwIsW9Iz8EJkTdykyA== + "@prisma/debug@6.3.1": version "6.3.1" resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-6.3.1.tgz#08730461dab4fe147efa70637952b942dc1961b5"