From 003d8a0f3e2b497878f2576dfce2ccbe031cb598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Csisz=C3=A1r?= Date: Sat, 4 May 2024 20:37:42 +0200 Subject: [PATCH 1/4] Done schema creation --- apps/backend/prisma/schema.prisma | 51 +++++++++++++++++++++++++++++-- yarn.lock | 49 +++++++++-------------------- 2 files changed, 63 insertions(+), 37 deletions(-) diff --git a/apps/backend/prisma/schema.prisma b/apps/backend/prisma/schema.prisma index ac63787..17a602f 100644 --- a/apps/backend/prisma/schema.prisma +++ b/apps/backend/prisma/schema.prisma @@ -13,7 +13,54 @@ datasource db { url = env("DATABASE_URL") } +enum Priority { + LOW + MEDIUM + HIGH +} + +enum Status { + OPEN + IN_PROGRESS + DONE +} + model User { - authSchId String @id - email String @unique + id Int @id @default(autoincrement()) + authSchId String + email String @unique + groups Group[] + profilePicture String? + events Event[] +} + +model Group { + id Int @id @default(autoincrement()) + name String + description String? + members User[] + events Event[] +} + +model Event { + id Int @id @default(autoincrement()) + name String + description String? + date DateTime + location String + categoryId Int + category Category @relation(fields: [categoryId], references: [id]) + priority Priority + status Status + ownerUserId Int? + ownerUser User? @relation(fields: [ownerUserId], references: [id]) + ownerGroupId Int? + ownerGroup Group? @relation(fields: [ownerGroupId], references: [id]) +} + +model Category { + id Int @id @default(autoincrement()) + name String + description String? + events Event[] } diff --git a/yarn.lock b/yarn.lock index bf36560..d4604f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1156,11 +1156,6 @@ ansi-styles@^4.0.0, ansi-styles@^4.1.0: dependencies: color-convert "^2.0.1" -ansi-styles@^6.1.0: - version "6.2.1" - resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-6.2.1.tgz#0e62320cf99c21afff3b3012192546aacbfb05c5" - integrity sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug== - any-promise@^1.0.0: version "1.3.0" resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f" @@ -1923,11 +1918,6 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" -eastasianwidth@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/eastasianwidth/-/eastasianwidth-0.2.0.tgz#696ce2ec0aa0e6ea93a397ffcf24aa7840c827cb" - integrity sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA== - ee-first@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" @@ -4727,7 +4717,7 @@ streamsearch@^1.1.0: resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764" integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg== -"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -4736,7 +4726,7 @@ streamsearch@^1.1.0: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.1" -string-width@^4.1.0: +string-width@4.1.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3, string-width@^5.1.2: version "4.1.0" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.1.0.tgz#ba846d1daa97c3c596155308063e075ed1c99aff" integrity sha512-NrX+1dVVh+6Y9dnQ19pR0pP4FiEIlUvdTGn8pw6CKTNq5sgib2nIhmUNT5TAmhWmvKr3WcxBcP3E8nWezuipuQ== @@ -4745,15 +4735,6 @@ string-width@^4.1.0: is-fullwidth-code-point "^3.0.0" strip-ansi "^5.2.0" -string-width@^5.0.1, string-width@^5.1.2: - version "5.1.2" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" - integrity sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA== - dependencies: - eastasianwidth "^0.2.0" - emoji-regex "^9.2.2" - strip-ansi "^7.0.1" - string.prototype.matchall@^4.0.10: version "4.0.11" resolved "https://registry.yarnpkg.com/string.prototype.matchall/-/string.prototype.matchall-4.0.11.tgz#1092a72c59268d2abaad76582dccc687c0297e0a" @@ -4814,7 +4795,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -4828,6 +4809,13 @@ strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" +strip-ansi@^6.0.0, strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -5431,24 +5419,15 @@ which@^2.0.1: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: - version "6.2.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" - integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA== +wrap-ansi@7.0.0, wrap-ansi@^6.0.1, wrap-ansi@^6.2.0, wrap-ansi@^8.1.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== dependencies: ansi-styles "^4.0.0" string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^8.1.0: - version "8.1.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" - integrity sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ== - dependencies: - ansi-styles "^6.1.0" - string-width "^5.0.1" - strip-ansi "^7.0.1" - wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" From 718c4eec007de0e348e6ec74fc7c336be209300a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Csisz=C3=A1r?= Date: Sat, 4 May 2024 22:10:58 +0200 Subject: [PATCH 2/4] Adds mapped types for nestjs --- apps/backend/package.json | 1 + yarn.lock | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/apps/backend/package.json b/apps/backend/package.json index abeb775..fc09a3a 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -16,6 +16,7 @@ "dependencies": { "@nestjs/common": "^10.3.8", "@nestjs/core": "^10.3.8", + "@nestjs/mapped-types": "*", "@nestjs/platform-express": "^10.3.8", "@prisma/client": "^5.13.0", "nestjs-prisma": "^0.23.0", diff --git a/yarn.lock b/yarn.lock index d4604f2..020f050 100644 --- a/yarn.lock +++ b/yarn.lock @@ -298,6 +298,11 @@ path-to-regexp "3.2.0" tslib "2.6.2" +"@nestjs/mapped-types@*": + version "2.0.5" + resolved "https://registry.yarnpkg.com/@nestjs/mapped-types/-/mapped-types-2.0.5.tgz#485d6b44e19779c98d04e52bd1d2bcc7001df0ea" + integrity sha512-bSJv4pd6EY99NX9CjBIyn4TVDoSit82DUZlL4I3bqNfy5Gt+gXTa86i3I/i0iIV9P4hntcGM5GyO+FhZAhxtyg== + "@nestjs/platform-express@^10.3.8": version "10.3.8" resolved "https://registry.yarnpkg.com/@nestjs/platform-express/-/platform-express-10.3.8.tgz#e8458cb1d1931589d5438d7b6075aa31634417d3" From 3aac7cdcfd4ba5411298b06b96d74a52776923f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Csisz=C3=A1r?= Date: Sat, 4 May 2024 22:21:08 +0200 Subject: [PATCH 3/4] Adds migrations --- .../20240504190930_init_db/migration.sql | 79 +++++++++++++++++++ .../migration.sql | 37 +++++++++ .../migration.sql | 19 +++++ .../prisma/migrations/migration_lock.toml | 3 + apps/backend/prisma/schema.prisma | 40 +++++++--- 5 files changed, 165 insertions(+), 13 deletions(-) create mode 100644 apps/backend/prisma/migrations/20240504190930_init_db/migration.sql create mode 100644 apps/backend/prisma/migrations/20240504195638_adds_role_for_group_users/migration.sql create mode 100644 apps/backend/prisma/migrations/20240504195717_event_has_only_one_owner/migration.sql create mode 100644 apps/backend/prisma/migrations/migration_lock.toml diff --git a/apps/backend/prisma/migrations/20240504190930_init_db/migration.sql b/apps/backend/prisma/migrations/20240504190930_init_db/migration.sql new file mode 100644 index 0000000..9f6beb3 --- /dev/null +++ b/apps/backend/prisma/migrations/20240504190930_init_db/migration.sql @@ -0,0 +1,79 @@ +-- CreateEnum +CREATE TYPE "Priority" AS ENUM ('LOW', 'MEDIUM', 'HIGH'); + +-- CreateEnum +CREATE TYPE "Status" AS ENUM ('OPEN', 'IN_PROGRESS', 'DONE'); + +-- CreateTable +CREATE TABLE "User" ( + "id" SERIAL NOT NULL, + "authSchId" TEXT NOT NULL, + "email" TEXT NOT NULL, + "profilePicture" TEXT, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Group" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "description" TEXT, + + CONSTRAINT "Group_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Event" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "description" TEXT, + "date" TIMESTAMP(3) NOT NULL, + "location" TEXT NOT NULL, + "categoryId" INTEGER NOT NULL, + "priority" "Priority" NOT NULL, + "status" "Status" NOT NULL, + "ownerUserId" INTEGER, + "ownerGroupId" INTEGER, + + CONSTRAINT "Event_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Category" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "description" TEXT, + + CONSTRAINT "Category_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "_GroupToUser" ( + "A" INTEGER NOT NULL, + "B" INTEGER NOT NULL +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "_GroupToUser_AB_unique" ON "_GroupToUser"("A", "B"); + +-- CreateIndex +CREATE INDEX "_GroupToUser_B_index" ON "_GroupToUser"("B"); + +-- AddForeignKey +ALTER TABLE "Event" ADD CONSTRAINT "Event_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Event" ADD CONSTRAINT "Event_ownerUserId_fkey" FOREIGN KEY ("ownerUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Event" ADD CONSTRAINT "Event_ownerGroupId_fkey" FOREIGN KEY ("ownerGroupId") REFERENCES "Group"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_GroupToUser" ADD CONSTRAINT "_GroupToUser_A_fkey" FOREIGN KEY ("A") REFERENCES "Group"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_GroupToUser" ADD CONSTRAINT "_GroupToUser_B_fkey" FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/backend/prisma/migrations/20240504195638_adds_role_for_group_users/migration.sql b/apps/backend/prisma/migrations/20240504195638_adds_role_for_group_users/migration.sql new file mode 100644 index 0000000..d72c7ae --- /dev/null +++ b/apps/backend/prisma/migrations/20240504195638_adds_role_for_group_users/migration.sql @@ -0,0 +1,37 @@ +/* + Warnings: + + - You are about to drop the column `location` on the `Event` table. All the data in the column will be lost. + - You are about to drop the `_GroupToUser` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- CreateEnum +CREATE TYPE "Role" AS ENUM ('ADMIN', 'USER'); + +-- DropForeignKey +ALTER TABLE "_GroupToUser" DROP CONSTRAINT "_GroupToUser_A_fkey"; + +-- DropForeignKey +ALTER TABLE "_GroupToUser" DROP CONSTRAINT "_GroupToUser_B_fkey"; + +-- AlterTable +ALTER TABLE "Event" DROP COLUMN "location", +ALTER COLUMN "date" SET DEFAULT CURRENT_TIMESTAMP; + +-- DropTable +DROP TABLE "_GroupToUser"; + +-- CreateTable +CREATE TABLE "GroupMembers" ( + "groupId" INTEGER NOT NULL, + "userId" INTEGER NOT NULL, + "role" "Role" NOT NULL DEFAULT 'USER', + + CONSTRAINT "GroupMembers_pkey" PRIMARY KEY ("groupId","userId") +); + +-- AddForeignKey +ALTER TABLE "GroupMembers" ADD CONSTRAINT "GroupMembers_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "Group"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "GroupMembers" ADD CONSTRAINT "GroupMembers_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/apps/backend/prisma/migrations/20240504195717_event_has_only_one_owner/migration.sql b/apps/backend/prisma/migrations/20240504195717_event_has_only_one_owner/migration.sql new file mode 100644 index 0000000..ebe8d75 --- /dev/null +++ b/apps/backend/prisma/migrations/20240504195717_event_has_only_one_owner/migration.sql @@ -0,0 +1,19 @@ +-- DropForeignKey +ALTER TABLE "Event" DROP CONSTRAINT "Event_ownerGroupId_fkey"; + +-- DropForeignKey +ALTER TABLE "Event" DROP CONSTRAINT "Event_ownerUserId_fkey"; + +-- AddForeignKey +ALTER TABLE "Event" ADD CONSTRAINT "Event_ownerUserId_fkey" FOREIGN KEY ("ownerUserId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Event" ADD CONSTRAINT "Event_ownerGroupId_fkey" FOREIGN KEY ("ownerGroupId") REFERENCES "Group"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- The Event table should have only one owner, either a user or a group. The ownerUserId and ownerGroupId columns should be mutually exclusive. If an event has an ownerUserId, it should not have an ownerGroupId, and vice versa. +ALTER TABLE IF EXISTS "Event" + ADD CONSTRAINT only_one_owner + CHECK ( + ("ownerUserId" IS NOT NULL AND "ownerGroupId" IS NULL) OR + ("ownerUserId" IS NULL AND "ownerGroupId" IS NOT NULL) + ); diff --git a/apps/backend/prisma/migrations/migration_lock.toml b/apps/backend/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..fbffa92 --- /dev/null +++ b/apps/backend/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 (i.e. Git) +provider = "postgresql" \ No newline at end of file diff --git a/apps/backend/prisma/schema.prisma b/apps/backend/prisma/schema.prisma index 17a602f..d6a8db5 100644 --- a/apps/backend/prisma/schema.prisma +++ b/apps/backend/prisma/schema.prisma @@ -25,41 +25,55 @@ enum Status { DONE } +enum Role { + ADMIN + USER +} + model User { - id Int @id @default(autoincrement()) - authSchId String + id Int @id @default(autoincrement()) + authSchId String //Ez majd a belepeshez kell email String @unique - groups Group[] profilePicture String? + groups GroupMembers[] events Event[] } model Group { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) name String description String? - members User[] + members GroupMembers[] events Event[] } +model GroupMembers { + groupId Int + userId Int + role Role @default(USER) + + @@id([groupId, userId]) + Group Group @relation(fields: [groupId], references: [id]) + User User @relation(fields: [userId], references: [id]) +} + model Event { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) name String description String? - date DateTime - location String - categoryId Int - category Category @relation(fields: [categoryId], references: [id]) + date DateTime @default(now()) priority Priority status Status + categoryId Int + category Category @relation(fields: [categoryId], references: [id]) ownerUserId Int? - ownerUser User? @relation(fields: [ownerUserId], references: [id]) + ownerUser User? @relation(fields: [ownerUserId], references: [id], onDelete: Cascade) ownerGroupId Int? - ownerGroup Group? @relation(fields: [ownerGroupId], references: [id]) + ownerGroup Group? @relation(fields: [ownerGroupId], references: [id], onDelete: Cascade) } model Category { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) name String description String? events Event[] From 5958ec974d3149a3446924e66c23930d5bf40551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Csisz=C3=A1r?= Date: Sun, 5 May 2024 12:10:47 +0200 Subject: [PATCH 4/4] Adds more fields to prisma schema --- .../migration.sql | 29 +++++++++++++++ apps/backend/prisma/schema.prisma | 35 +++++++++++-------- 2 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 apps/backend/prisma/migrations/20240505100416_edit_schame_based_1_issue/migration.sql diff --git a/apps/backend/prisma/migrations/20240505100416_edit_schame_based_1_issue/migration.sql b/apps/backend/prisma/migrations/20240505100416_edit_schame_based_1_issue/migration.sql new file mode 100644 index 0000000..fdbcd39 --- /dev/null +++ b/apps/backend/prisma/migrations/20240505100416_edit_schame_based_1_issue/migration.sql @@ -0,0 +1,29 @@ +/* + Warnings: + + - The values [OPEN] on the enum `Status` will be removed. If these variants are still used in the database, this will fail. + - You are about to drop the column `date` on the `Event` table. All the data in the column will be lost. + - Added the required column `color` to the `Category` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterEnum +ALTER TYPE "Priority" ADD VALUE 'URGENT'; + +-- AlterEnum +BEGIN; +ALTER TYPE "Status" ADD VALUE 'WAITING_FOR_REVIEW'; +ALTER TYPE "Status" RENAME VALUE 'OPEN' TO 'NOT_STARTED'; +COMMIT; + +-- AlterTable +ALTER TABLE "Category" ADD COLUMN "color" TEXT NOT NULL DEFAULT '#000000'; + +-- AlterTable +ALTER TABLE "Event" DROP COLUMN "date", +ADD COLUMN "endDate" DATE, +ADD COLUMN "endTime" TIME, +ADD COLUMN "location" TEXT, +ADD COLUMN "startDate" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "startTime" TIME, +ALTER COLUMN "priority" SET DEFAULT 'MEDIUM', +ALTER COLUMN "status" SET DEFAULT 'NOT_STARTED'; diff --git a/apps/backend/prisma/schema.prisma b/apps/backend/prisma/schema.prisma index d6a8db5..29b8ed6 100644 --- a/apps/backend/prisma/schema.prisma +++ b/apps/backend/prisma/schema.prisma @@ -17,11 +17,13 @@ enum Priority { LOW MEDIUM HIGH + URGENT } enum Status { - OPEN + NOT_STARTED IN_PROGRESS + WAITING_FOR_REVIEW DONE } @@ -31,16 +33,16 @@ enum Role { } model User { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) authSchId String //Ez majd a belepeshez kell - email String @unique + email String @unique profilePicture String? groups GroupMembers[] events Event[] } model Group { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) name String description String? members GroupMembers[] @@ -50,31 +52,36 @@ model Group { model GroupMembers { groupId Int userId Int - role Role @default(USER) - - @@id([groupId, userId]) + role Role @default(USER) Group Group @relation(fields: [groupId], references: [id]) User User @relation(fields: [userId], references: [id]) + + @@id([groupId, userId]) } model Event { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) name String description String? - date DateTime @default(now()) - priority Priority - status Status + location String? + startDate DateTime @default(now()) @db.Date + endDate DateTime? @db.Date + startTime DateTime? @db.Time + endTime DateTime? @db.Time + priority Priority @default(MEDIUM) + status Status @default(NOT_STARTED) categoryId Int - category Category @relation(fields: [categoryId], references: [id]) + category Category @relation(fields: [categoryId], references: [id]) ownerUserId Int? - ownerUser User? @relation(fields: [ownerUserId], references: [id], onDelete: Cascade) + ownerUser User? @relation(fields: [ownerUserId], references: [id], onDelete: Cascade) ownerGroupId Int? - ownerGroup Group? @relation(fields: [ownerGroupId], references: [id], onDelete: Cascade) + ownerGroup Group? @relation(fields: [ownerGroupId], references: [id], onDelete: Cascade) } model Category { id Int @id @default(autoincrement()) name String + color String @default("#000000") description String? events Event[] }