mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +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
|
-- CreateTable
|
||||||
CREATE TABLE "Course" (
|
CREATE TABLE "Course" (
|
||||||
"id" SERIAL NOT NULL,
|
"id" SERIAL NOT NULL,
|
||||||
|
"userId" INTEGER NOT NULL,
|
||||||
"price" INTEGER NOT NULL DEFAULT 0,
|
"price" INTEGER NOT NULL DEFAULT 0,
|
||||||
"noteId" TEXT,
|
"noteId" TEXT,
|
||||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
@ -46,6 +47,7 @@ CREATE TABLE "Course" (
|
|||||||
-- CreateTable
|
-- CreateTable
|
||||||
CREATE TABLE "Resource" (
|
CREATE TABLE "Resource" (
|
||||||
"id" SERIAL NOT NULL,
|
"id" SERIAL NOT NULL,
|
||||||
|
"userId" INTEGER NOT NULL,
|
||||||
"courseId" INTEGER,
|
"courseId" INTEGER,
|
||||||
"price" INTEGER NOT NULL DEFAULT 0,
|
"price" INTEGER NOT NULL DEFAULT 0,
|
||||||
"noteId" TEXT,
|
"noteId" TEXT,
|
||||||
@ -79,5 +81,11 @@ ALTER TABLE "Purchase" ADD CONSTRAINT "Purchase_courseId_fkey" FOREIGN KEY ("cou
|
|||||||
-- AddForeignKey
|
-- AddForeignKey
|
||||||
ALTER TABLE "Purchase" ADD CONSTRAINT "Purchase_resourceId_fkey" FOREIGN KEY ("resourceId") REFERENCES "Resource"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
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
|
-- AddForeignKey
|
||||||
ALTER TABLE "Resource" ADD CONSTRAINT "Resource_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
ALTER TABLE "Resource" ADD CONSTRAINT "Resource_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
@ -13,6 +13,8 @@ model User {
|
|||||||
username String? @unique
|
username String? @unique
|
||||||
avatar String?
|
avatar String?
|
||||||
purchased Purchase[]
|
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])
|
role Role? @relation(fields: [roleId], references: [id])
|
||||||
roleId Int?
|
roleId Int?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
@ -41,6 +43,8 @@ model Purchase {
|
|||||||
|
|
||||||
model Course {
|
model Course {
|
||||||
id Int @id @default(autoincrement())
|
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)
|
price Int @default(0)
|
||||||
resources Resource[]
|
resources Resource[]
|
||||||
purchases Purchase[]
|
purchases Purchase[]
|
||||||
@ -51,6 +55,8 @@ model Course {
|
|||||||
|
|
||||||
model Resource {
|
model Resource {
|
||||||
id Int @id @default(autoincrement())
|
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])
|
course Course? @relation(fields: [courseId], references: [id])
|
||||||
courseId Int?
|
courseId Int?
|
||||||
price Int @default(0)
|
price Int @default(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user