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

fix: userid update #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions prisma/migrations/20240924073131_clang/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Blog" ADD COLUMN "language" TEXT NOT NULL DEFAULT 'english';
170 changes: 170 additions & 0 deletions prisma/migrations/20240924094053_clang2/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
Warnings:

- The primary key for the `Answer` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The `userId` column on the `Answer` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The primary key for the `Blog` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The `userId` column on the `Blog` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The primary key for the `MedicalQuery` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The `userId` column on the `MedicalQuery` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The `surveyId` column on the `Question` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The `userId` column on the `Quiz` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The primary key for the `SleepData` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The `userId` column on the `SleepData` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The primary key for the `Survey` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The `userId` column on the `Survey` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The primary key for the `Task` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The `userId` column on the `Task` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The `issuedById` column on the `Task` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint.
- Changed the type of `id` on the `Answer` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `id` on the `Blog` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `id` on the `MedicalQuery` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `id` on the `SleepData` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `id` on the `Survey` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `id` on the `Task` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `id` on the `User` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.

*/
-- DropForeignKey
ALTER TABLE "Answer" DROP CONSTRAINT "Answer_userId_fkey";

-- DropForeignKey
ALTER TABLE "Blog" DROP CONSTRAINT "Blog_userId_fkey";

-- DropForeignKey
ALTER TABLE "MedicalQuery" DROP CONSTRAINT "MedicalQuery_userId_fkey";

-- DropForeignKey
ALTER TABLE "Question" DROP CONSTRAINT "Question_surveyId_fkey";

-- DropForeignKey
ALTER TABLE "Quiz" DROP CONSTRAINT "Quiz_userId_fkey";

-- DropForeignKey
ALTER TABLE "SleepData" DROP CONSTRAINT "SleepData_userId_fkey";

-- DropForeignKey
ALTER TABLE "Survey" DROP CONSTRAINT "Survey_userId_fkey";

-- DropForeignKey
ALTER TABLE "Task" DROP CONSTRAINT "Task_issuedById_fkey";

-- DropForeignKey
ALTER TABLE "Task" DROP CONSTRAINT "Task_userId_fkey";

-- AlterTable
ALTER TABLE "Answer" DROP CONSTRAINT "Answer_pkey",
DROP COLUMN "id",
ADD COLUMN "id" UUID NOT NULL,
DROP COLUMN "userId",
ADD COLUMN "userId" UUID,
ADD CONSTRAINT "Answer_pkey" PRIMARY KEY ("id");

-- AlterTable
ALTER TABLE "Blog" DROP CONSTRAINT "Blog_pkey",
DROP COLUMN "id",
ADD COLUMN "id" UUID NOT NULL,
DROP COLUMN "userId",
ADD COLUMN "userId" UUID,
ADD CONSTRAINT "Blog_pkey" PRIMARY KEY ("id");

-- AlterTable
ALTER TABLE "MedicalQuery" DROP CONSTRAINT "MedicalQuery_pkey",
DROP COLUMN "id",
ADD COLUMN "id" UUID NOT NULL,
DROP COLUMN "userId",
ADD COLUMN "userId" UUID,
ADD CONSTRAINT "MedicalQuery_pkey" PRIMARY KEY ("id");

-- AlterTable
ALTER TABLE "Question" DROP COLUMN "surveyId",
ADD COLUMN "surveyId" UUID;

-- AlterTable
ALTER TABLE "Quiz" DROP COLUMN "userId",
ADD COLUMN "userId" UUID;

-- AlterTable
ALTER TABLE "SleepData" DROP CONSTRAINT "SleepData_pkey",
DROP COLUMN "id",
ADD COLUMN "id" UUID NOT NULL,
DROP COLUMN "userId",
ADD COLUMN "userId" UUID,
ADD CONSTRAINT "SleepData_pkey" PRIMARY KEY ("id");

-- AlterTable
ALTER TABLE "Survey" DROP CONSTRAINT "Survey_pkey",
DROP COLUMN "id",
ADD COLUMN "id" UUID NOT NULL,
DROP COLUMN "userId",
ADD COLUMN "userId" UUID,
ADD CONSTRAINT "Survey_pkey" PRIMARY KEY ("id");

-- AlterTable
ALTER TABLE "Task" DROP CONSTRAINT "Task_pkey",
DROP COLUMN "id",
ADD COLUMN "id" UUID NOT NULL,
DROP COLUMN "userId",
ADD COLUMN "userId" UUID,
DROP COLUMN "issuedById",
ADD COLUMN "issuedById" UUID,
ADD CONSTRAINT "Task_pkey" PRIMARY KEY ("id");

-- AlterTable
ALTER TABLE "User" DROP CONSTRAINT "User_pkey",
ADD COLUMN "language" TEXT NOT NULL DEFAULT 'english',
DROP COLUMN "id",
ADD COLUMN "id" UUID NOT NULL,
ADD CONSTRAINT "User_pkey" PRIMARY KEY ("id");

-- CreateIndex
CREATE INDEX "Answer_userId_idx" ON "Answer"("userId");

-- CreateIndex
CREATE INDEX "Blog_userId_idx" ON "Blog"("userId");

-- CreateIndex
CREATE INDEX "MedicalQuery_userId_idx" ON "MedicalQuery"("userId");

-- CreateIndex
CREATE INDEX "Question_surveyId_idx" ON "Question"("surveyId");

-- CreateIndex
CREATE INDEX "SleepData_userId_idx" ON "SleepData"("userId");

-- CreateIndex
CREATE INDEX "Survey_userId_idx" ON "Survey"("userId");

-- CreateIndex
CREATE INDEX "Task_userId_idx" ON "Task"("userId");

-- CreateIndex
CREATE INDEX "Task_issuedById_idx" ON "Task"("issuedById");

-- AddForeignKey
ALTER TABLE "Blog" ADD CONSTRAINT "Blog_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Task" ADD CONSTRAINT "Task_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Task" ADD CONSTRAINT "Task_issuedById_fkey" FOREIGN KEY ("issuedById") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "SleepData" ADD CONSTRAINT "SleepData_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Survey" ADD CONSTRAINT "Survey_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Quiz" ADD CONSTRAINT "Quiz_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Question" ADD CONSTRAINT "Question_surveyId_fkey" FOREIGN KEY ("surveyId") REFERENCES "Survey"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Answer" ADD CONSTRAINT "Answer_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MedicalQuery" ADD CONSTRAINT "MedicalQuery_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
64 changes: 35 additions & 29 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ datasource db {

// User model represents the application users
model User {
id Int @id @default(autoincrement())
name String @db.VarChar(100)
age Int
birthday DateTime
location String @db.VarChar(255)
gender Gender
email String @unique @db.VarChar(255)
contact String @db.VarChar(20)
picture String @db.VarChar(255)
position Position
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
id String @id @default(uuid()) @db.Uuid
name String @db.VarChar(100)
age Int
birthday DateTime
language String @default("english")
location String @db.VarChar(255)
gender Gender
email String @unique @db.VarChar(255)
contact String @db.VarChar(20)
picture String @db.VarChar(255)
position Position
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relations
blogs Blog[]
tasks Task[] @relation("UserTasks")
issuedTasks Task[] @relation("IssuedTasks")
Expand Down Expand Up @@ -50,33 +53,35 @@ enum Position {

// Blog model represents blog posts authored by users
model Blog {
id Int @id @default(autoincrement())
id String @id @default(uuid()) @db.Uuid
title String @db.VarChar(255)
picture String @db.VarChar(255)
content String @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
authorName String @db.VarChar(100)
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int?
userId String? @db.Uuid
region String @default("general")

language String @default("english")

@@index([userId])
@@index([title])
}

// Task model represents tasks associated with users
model Task {
id Int @id @default(autoincrement())
id String @id @default(uuid()) @db.Uuid
date DateTime
taskName String @db.VarChar(255)
status TaskStatus
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User? @relation(name: "UserTasks", fields: [userId], references: [id], onDelete: Cascade)
userId Int?
userId String? @db.Uuid
issuedBy User? @relation(name: "IssuedTasks", fields: [issuedById], references: [id], onDelete: SetNull)
issuedById Int?
issuedById String? @db.Uuid

@@index([userId])
@@index([issuedById])
Expand All @@ -91,15 +96,15 @@ enum TaskStatus {

// SleepData model represents sleep data associated with users
model SleepData {
id Int @id @default(autoincrement())
id String @id @default(uuid()) @db.Uuid
date DateTime
sleepStart DateTime
sleepEnd DateTime
sleepType SleepType
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int?
userId String? @db.Uuid

@@index([userId])
}
Expand All @@ -113,32 +118,33 @@ enum SleepType {

// Survey model represents surveys created by users
model Survey {
id Int @id @default(autoincrement())
id String @id @default(uuid()) @db.Uuid
topic String @default("question") @db.VarChar(255)
description String @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int?
userId String? @db.Uuid
questions Question[]

@@index([userId])
@@index([topic])
}

// Quiz model represents quizzes created by users
model Quiz {
id Int @id @default(autoincrement())
topic String @default("periods") @db.VarChar(255)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
questions Question[]
userId Int?
userId String? @db.Uuid
user User? @relation(fields: [userId], references: [id])

@@index([topic])
}

// Question model represents questions in surveys
// Question model represents questions in surveys or quizzes
model Question {
id Int @id @default(autoincrement())
text String @db.Text
Expand All @@ -151,7 +157,7 @@ model Question {
updatedAt DateTime @updatedAt

survey Survey? @relation(fields: [surveyId], references: [id], onDelete: Cascade)
surveyId Int?
surveyId String? @db.Uuid

Quiz Quiz? @relation(fields: [quizId], references: [id])
quizId Int?
Expand All @@ -166,14 +172,14 @@ enum QuestionType {
BOOLEAN
}

// Answer model represents answers to survey questions
// Answer model represents answers to survey or quiz questions
model Answer {
id Int @id @default(autoincrement())
id String @id @default(uuid()) @db.Uuid
response String @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int?
userId String? @db.Uuid
question Question? @relation(fields: [questionId], references: [id], onDelete: Cascade)
questionId Int?

Expand All @@ -183,14 +189,14 @@ model Answer {

// MedicalQuery model represents medical queries made by users
model MedicalQuery {
id Int @id @default(autoincrement())
id String @id @default(uuid()) @db.Uuid
query String @db.Text
response String @db.Text
status QueryStatus
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int?
userId String? @db.Uuid

@@index([userId])
}
Expand Down
Loading