mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-04-19 19:01:19 +00:00
Update schema to allow users to post resources/workshops
This commit is contained in:
parent
7abf1c8882
commit
0e6c2c7e25
@ -35,6 +35,7 @@ CREATE TABLE "Purchase" (
|
||||
-- CreateTable
|
||||
CREATE TABLE "Course" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"price" INTEGER NOT NULL DEFAULT 0,
|
||||
"noteId" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
@ -46,6 +47,7 @@ CREATE TABLE "Course" (
|
||||
-- CreateTable
|
||||
CREATE TABLE "Resource" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"courseId" INTEGER,
|
||||
"price" INTEGER NOT NULL DEFAULT 0,
|
||||
"noteId" TEXT,
|
||||
@ -79,5 +81,11 @@ ALTER TABLE "Purchase" ADD CONSTRAINT "Purchase_courseId_fkey" FOREIGN KEY ("cou
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Purchase" ADD CONSTRAINT "Purchase_resourceId_fkey" FOREIGN KEY ("resourceId") REFERENCES "Resource"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Course" ADD CONSTRAINT "Course_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Resource" ADD CONSTRAINT "Resource_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Resource" ADD CONSTRAINT "Resource_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
@ -8,15 +8,17 @@ generator client {
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
pubkey String @unique
|
||||
username String? @unique
|
||||
avatar String?
|
||||
purchased Purchase[]
|
||||
role Role? @relation(fields: [roleId], references: [id])
|
||||
roleId Int?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id Int @id @default(autoincrement())
|
||||
pubkey String @unique
|
||||
username String? @unique
|
||||
avatar String?
|
||||
purchased Purchase[]
|
||||
courses Course[] // Relation field added for courses created by the user
|
||||
resources Resource[] // Relation field added for resources created by the user
|
||||
role Role? @relation(fields: [roleId], references: [id])
|
||||
roleId Int?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model Role {
|
||||
@ -41,6 +43,8 @@ model Purchase {
|
||||
|
||||
model Course {
|
||||
id Int @id @default(autoincrement())
|
||||
userId Int // Field added to link a course to a user
|
||||
user User @relation(fields: [userId], references: [id]) // Relation setup for user
|
||||
price Int @default(0)
|
||||
resources Resource[]
|
||||
purchases Purchase[]
|
||||
@ -51,6 +55,8 @@ model Course {
|
||||
|
||||
model Resource {
|
||||
id Int @id @default(autoincrement())
|
||||
userId Int // Field added to link a resource to a user
|
||||
user User @relation(fields: [userId], references: [id]) // Relation setup for user
|
||||
course Course? @relation(fields: [courseId], references: [id])
|
||||
courseId Int?
|
||||
price Int @default(0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user