Skip to content

Commit

Permalink
update schema and prep for new db
Browse files Browse the repository at this point in the history
  • Loading branch information
DCRepublic committed Oct 3, 2024
1 parent 1d2f6be commit f655fa9
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 33 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,37 @@

Install [Golang](https://go.dev/dl/)

```bash
npm install
```

### Run the development server

```bash
cd YOUR_WORKING_DIR
docker compose -f docker-compose.debug.yml up -d
cd swatscraper
```

first run only:

```bash
go mod init github.com/swatscraper
go mod tidy
```

```bash
go run main.go
```

### View the dev site

Head on over to http://localhost:3000

### View the db vizually

```bash
npx prisma studio
```

Head on over to http://localhost:5555

## License

Licensed under the [MIT license](https://github.com/swat-sccs/scheduler-v2/blob/main/LICENSE).
5 changes: 3 additions & 2 deletions app/api/test/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// api/test.ts
import type { NextApiRequest, NextApiResponse } from "next";

import { NextResponse, NextRequest } from "next/server";

import prisma from "@/lib/prisma";

export async function GET(request: NextRequest) {
const users = await prisma.User.findMany();
const users = await prisma.faculty.findMany();

return NextResponse.json(users, { status: 200 });
}
Expand Down
52 changes: 52 additions & 0 deletions prisma/migrations/20241002193050_courses2/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Warnings:
- You are about to drop the column `facultyId` on the `Course` table. All the data in the column will be lost.
- You are about to drop the column `facultyMeetId` on the `Course` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "Course" DROP CONSTRAINT "Course_facultyId_fkey";

-- DropForeignKey
ALTER TABLE "Course" DROP CONSTRAINT "Course_facultyMeetId_fkey";

-- AlterTable
ALTER TABLE "Course" DROP COLUMN "facultyId",
DROP COLUMN "facultyMeetId";

-- CreateTable
CREATE TABLE "_CourseToFaculty" (
"A" INTEGER NOT NULL,
"B" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "_CourseToMeetingsFaculty" (
"A" INTEGER NOT NULL,
"B" INTEGER NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "_CourseToFaculty_AB_unique" ON "_CourseToFaculty"("A", "B");

-- CreateIndex
CREATE INDEX "_CourseToFaculty_B_index" ON "_CourseToFaculty"("B");

-- CreateIndex
CREATE UNIQUE INDEX "_CourseToMeetingsFaculty_AB_unique" ON "_CourseToMeetingsFaculty"("A", "B");

-- CreateIndex
CREATE INDEX "_CourseToMeetingsFaculty_B_index" ON "_CourseToMeetingsFaculty"("B");

-- AddForeignKey
ALTER TABLE "_CourseToFaculty" ADD CONSTRAINT "_CourseToFaculty_A_fkey" FOREIGN KEY ("A") REFERENCES "Course"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_CourseToFaculty" ADD CONSTRAINT "_CourseToFaculty_B_fkey" FOREIGN KEY ("B") REFERENCES "Faculty"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_CourseToMeetingsFaculty" ADD CONSTRAINT "_CourseToMeetingsFaculty_A_fkey" FOREIGN KEY ("A") REFERENCES "Course"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_CourseToMeetingsFaculty" ADD CONSTRAINT "_CourseToMeetingsFaculty_B_fkey" FOREIGN KEY ("B") REFERENCES "MeetingsFaculty"("id") ON DELETE CASCADE ON UPDATE CASCADE;
36 changes: 36 additions & 0 deletions prisma/migrations/20241002194124_courses3/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Warnings:
- You are about to drop the `_CourseToFaculty` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `_CourseToMeetingsFaculty` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `facultyId` to the `Course` table without a default value. This is not possible if the table is not empty.
- Added the required column `facultyMeetId` to the `Course` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE "_CourseToFaculty" DROP CONSTRAINT "_CourseToFaculty_A_fkey";

-- DropForeignKey
ALTER TABLE "_CourseToFaculty" DROP CONSTRAINT "_CourseToFaculty_B_fkey";

-- DropForeignKey
ALTER TABLE "_CourseToMeetingsFaculty" DROP CONSTRAINT "_CourseToMeetingsFaculty_A_fkey";

-- DropForeignKey
ALTER TABLE "_CourseToMeetingsFaculty" DROP CONSTRAINT "_CourseToMeetingsFaculty_B_fkey";

-- AlterTable
ALTER TABLE "Course" ADD COLUMN "facultyId" INTEGER NOT NULL,
ADD COLUMN "facultyMeetId" INTEGER NOT NULL;

-- DropTable
DROP TABLE "_CourseToFaculty";

-- DropTable
DROP TABLE "_CourseToMeetingsFaculty";

-- AddForeignKey
ALTER TABLE "Course" ADD CONSTRAINT "Course_facultyId_fkey" FOREIGN KEY ("facultyId") REFERENCES "Faculty"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Course" ADD CONSTRAINT "Course_facultyMeetId_fkey" FOREIGN KEY ("facultyMeetId") REFERENCES "MeetingsFaculty"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
24 changes: 24 additions & 0 deletions prisma/migrations/20241002214740_courses4/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- AlterTable
ALTER TABLE "Course" ALTER COLUMN "courseReferenceNumber" SET DATA TYPE TEXT,
ALTER COLUMN "courseNumber" SET DATA TYPE TEXT,
ALTER COLUMN "creditHours" SET DATA TYPE DOUBLE PRECISION;

-- AlterTable
ALTER TABLE "Faculty" ALTER COLUMN "bannerId" SET DATA TYPE TEXT,
ALTER COLUMN "courseReferenceNumber" SET DATA TYPE TEXT;

-- AlterTable
ALTER TABLE "MeetingTime" ALTER COLUMN "beginTime" SET DATA TYPE TEXT,
ALTER COLUMN "room" SET DATA TYPE TEXT,
ALTER COLUMN "category" SET DATA TYPE TEXT,
ALTER COLUMN "courseReferenceNumber" SET DATA TYPE TEXT,
ALTER COLUMN "endDate" SET DATA TYPE TEXT,
ALTER COLUMN "endTime" SET DATA TYPE TEXT,
ALTER COLUMN "hoursWeek" SET DATA TYPE DOUBLE PRECISION;

-- AlterTable
ALTER TABLE "MeetingsFaculty" ALTER COLUMN "category" SET DATA TYPE TEXT,
ALTER COLUMN "courseReferenceNumber" SET DATA TYPE TEXT;

-- AlterTable
ALTER TABLE "sectionAttribute" ALTER COLUMN "courseReferenceNumber" SET DATA TYPE TEXT;
46 changes: 20 additions & 26 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
}
Expand All @@ -23,64 +17,64 @@ model User {
model CoursePlan {
id Int @id @default(autoincrement())
name String
userId Int?
courses Course[]
User User? @relation(fields: [userId], references: [id])
userId Int?
}

model Course {
id Int @id @default(autoincrement())
courseId Int
courseReferenceNumber Int
courseNumber Int
courseReferenceNumber String
courseNumber String
subject String
scheduleTypeDescription String
courseTitle String
descriptionUrl String
description String
creditHours Int
creditHours Float
maximumEnrollment Int
enrollment Int
seatsAvailable Int
instructor Faculty @relation(fields: [facultyId], references: [id])
facultyId Int
facultyMeet MeetingsFaculty @relation(fields: [facultyMeetId], references: [id])
facultyMeetId Int
instructor Faculty @relation(fields: [facultyId], references: [id])
facultyMeet MeetingsFaculty @relation(fields: [facultyMeetId], references: [id])
sectionAttributes sectionAttribute[]
CoursePlan CoursePlan? @relation(fields: [coursePlanId], references: [id])
coursePlanId Int?
}

model Faculty {
id Int @id @default(autoincrement())
bannerId Int
courseReferenceNumber Int
bannerId String
courseReferenceNumber String
displayName String
emailAddress String
courses Course[]
}

model MeetingsFaculty {
id Int @id @default(autoincrement())
category Int
courseReferenceNumber Int
meetingTimes MeetingTime @relation(fields: [meetingTimeID], references: [id])
category String
courseReferenceNumber String
meetingTimeID Int
courses Course[]
meetingTimes MeetingTime @relation(fields: [meetingTimeID], references: [id])
}

model MeetingTime {
id Int @id @default(autoincrement())
beginTime Int
beginTime String
building String
buildingDescription String
room Int
category Int
courseReferenceNumber Int
endDate Int
endTime Int
room String
category String
courseReferenceNumber String
endDate String
endTime String
startDate String
hoursWeek Int
hoursWeek Float
meetingType String
meetingTypeDescription String
monday Boolean
Expand All @@ -97,7 +91,7 @@ model sectionAttribute {
id Int @id @default(autoincrement())
code String
description String
courseReferenceNumber Int
Course Course? @relation(fields: [courseId], references: [id])
courseReferenceNumber String
courseId Int?
Course Course? @relation(fields: [courseId], references: [id])
}
2 changes: 1 addition & 1 deletion swatscraper
Submodule swatscraper updated 2 files
+10 −4 README.md
+337 −40 main.go

0 comments on commit f655fa9

Please sign in to comment.