Skip to content

Commit

Permalink
feat: add borrow prisma schema
Browse files Browse the repository at this point in the history
  • Loading branch information
joseandrestrujillo committed Nov 22, 2023
1 parent f12f48a commit 0dee8b4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
18 changes: 18 additions & 0 deletions prisma/migrations/20231122165948_borrow/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- CreateTable
CREATE TABLE "Borrow" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"bookId" TEXT NOT NULL,
"borrowedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "Borrow_bookId_key" ON "Borrow"("bookId");

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

-- AddForeignKey
ALTER TABLE "Borrow" ADD CONSTRAINT "Borrow_bookId_fkey" FOREIGN KEY ("bookId") REFERENCES "Book"("id") ON DELETE CASCADE ON UPDATE CASCADE;
50 changes: 32 additions & 18 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ generator client {
}

model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Expand All @@ -41,9 +41,10 @@ model User {
email String? @unique
emailVerified DateTime?
image String?
roles String[] @default(["ROLE_USER"])
roles String[] @default(["ROLE_USER"])
accounts Account[]
sessions Session[]
Borrow Borrow[]
}

model VerificationToken {
Expand All @@ -55,8 +56,21 @@ model VerificationToken {
}

model Book {
id String @id @default(cuid())
authors String[]
image String
title String
}
id String @id @default(cuid())
authors String[]
image String
title String
Borrow Borrow?
}

model Borrow {
id String @id @default(cuid())
userId String
bookId String
borrowedAt DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
@@unique([bookId])
}

0 comments on commit 0dee8b4

Please sign in to comment.