Skip to content

Commit

Permalink
feat(db): database schema updates (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
nganphan123 authored Nov 24, 2023
1 parent 784050d commit bc8337b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 21 deletions.
10 changes: 0 additions & 10 deletions app/web/db/migrations/20231030110408_v0_1_0_dev/migration.sql

This file was deleted.

45 changes: 45 additions & 0 deletions app/web/db/migrations/20231124063103_v0_1_0_dev/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- CreateEnum
CREATE TYPE "Role" AS ENUM ('CLIENT', 'PROFESSIONAL');

-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"username" TEXT NOT NULL,
"password" TEXT NOT NULL,
"email" TEXT NOT NULL,
"firstname" TEXT NOT NULL,
"lastname" TEXT NOT NULL,
"role" "Role" NOT NULL,

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

-- CreateTable
CREATE TABLE "Appointment" (
"id" SERIAL NOT NULL,
"proId" INTEGER NOT NULL,
"clientId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "Video" (
"apptId" INTEGER NOT NULL,
"awsRef" TEXT NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");

-- CreateIndex
CREATE UNIQUE INDEX "Video_awsRef_key" ON "Video"("awsRef");

-- AddForeignKey
ALTER TABLE "Appointment" ADD CONSTRAINT "Appointment_proId_fkey" FOREIGN KEY ("proId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Appointment" ADD CONSTRAINT "Appointment_clientId_fkey" FOREIGN KEY ("clientId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Video" ADD CONSTRAINT "Video_apptId_fkey" FOREIGN KEY ("apptId") REFERENCES "Appointment"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
2 changes: 1 addition & 1 deletion app/web/db/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
provider = "postgresql"
10 changes: 5 additions & 5 deletions app/web/db/sample/user.properties.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
id,email,firstname,lastname,username
1,testuser1@gmail.com,user1,test,testuser1
2,testuser@gmail.com,user2,test,testuser2
3,testuser3@gmail.com,user3,test,testuser3
4,testuser4@gmail.com,user4,test,testuser4
id,email,firstname,lastname,username,password,role
1,testuser1@gmail.com,user1,test,testuser1,password,CLIENT
2,testuser@gmail.com,user2,test,testuser2,password,CLIENT
3,testuser3@gmail.com,user3,test,testuser3,password,PROFESSIONAL
4,testuser4@gmail.com,user4,test,testuser4,password,PROFESSIONAL
34 changes: 29 additions & 5 deletions app/web/db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,33 @@ datasource db {
}

model User {
id Int @id @default(autoincrement())
username String
email String
firstname String
lastname String
id Int @id @default(autoincrement())
username String @unique
password String
email String
firstname String
lastname String
role Role
proInApptWith Appointment[] @relation("proInApptWith")
clientInApptWith Appointment[] @relation("clientInApptWith")
}

model Appointment {
id Int @id @default(autoincrement())
professional User @relation(name: "proInApptWith", fields: [proId], references: [id])
proId Int
client User @relation(name: "clientInApptWith", fields: [clientId], references: [id])
clientId Int
Video Video[]
}

model Video {
appt Appointment @relation(fields: [apptId], references: [id])
apptId Int
awsRef String @unique
}

enum Role {
CLIENT
PROFESSIONAL
}

0 comments on commit bc8337b

Please sign in to comment.