Skip to content

Commit

Permalink
Merge pull request #5 from unovil/mysql-addition
Browse files Browse the repository at this point in the history
MySQL addition, Prisma and Lucia Integration
  • Loading branch information
unovil authored Mar 6, 2024
2 parents ee9ca09 + 53a43b5 commit 8d12cba
Show file tree
Hide file tree
Showing 26 changed files with 3,926 additions and 1,732 deletions.
4,811 changes: 3,100 additions & 1,711 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,36 @@
"test": "vitest"
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.5.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/svelte": "^4.1.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.17",
"autoprefixer": "^10.4.17",
"jsdom": "^24.0.0",
"lucia": "^3.0.1",
"postcss": "^8.4.35",
"prisma": "^5.10.2",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"tailwindcss": "^3.4.1",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"tsx": "^4.7.1",
"typescript": "^5.3.3",
"vite": "^5.0.3",
"vitest": "^1.2.2"
},
"type": "module"
"type": "module",
"prisma": {
"seed": "tsx prisma/seed.ts"
},
"dependencies": {
"@lucia-auth/adapter-prisma": "^4.0.0",
"@prisma/client": "^5.10.2",
"oslo": "^1.1.3",
"prisma-json-types-generator": "^3.0.4"
}
}
183 changes: 183 additions & 0 deletions prisma/migrations/20240228054355_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
-- CreateTable
CREATE TABLE `User` (
`id` VARCHAR(191) NOT NULL,
`email` VARCHAR(191) NULL,
`firstName` VARCHAR(191) NOT NULL,
`middleName` VARCHAR(191) NULL,
`lastName` VARCHAR(191) NOT NULL,
`password` VARCHAR(191) NOT NULL,
`role` ENUM('STUDENT', 'ADMIN') NOT NULL DEFAULT 'STUDENT',
`schoolId` INTEGER NULL,

UNIQUE INDEX `User_email_key`(`email`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `School` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Section` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`grade` INTEGER NOT NULL,
`name` VARCHAR(191) NOT NULL,
`schoolId` INTEGER NOT NULL,

UNIQUE INDEX `Section_name_key`(`name`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Admin` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`userId` VARCHAR(191) NOT NULL,
`departments` JSON NOT NULL,

UNIQUE INDEX `Admin_userId_key`(`userId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Student` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`lrn` CHAR(12) NOT NULL,
`sectionId` INTEGER NOT NULL,
`userId` VARCHAR(191) NOT NULL,

UNIQUE INDEX `Student_lrn_key`(`lrn`),
UNIQUE INDEX `Student_userId_key`(`userId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Facility` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`schoolId` INTEGER NOT NULL,
`name` VARCHAR(191) NOT NULL,
`department` ENUM('SCIENCE', 'MATH', 'MAPEH', 'MISC', 'LANGUAGE') NOT NULL DEFAULT 'MISC',
`blockedDates` JSON NOT NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Equipment` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`schoolId` INTEGER NOT NULL,
`name` VARCHAR(191) NOT NULL,
`department` ENUM('SCIENCE', 'MATH', 'MAPEH', 'MISC', 'LANGUAGE') NOT NULL DEFAULT 'MISC',
`blockedDates` JSON NOT NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Request` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`description` VARCHAR(191) NOT NULL,
`isAllowed` BOOLEAN NOT NULL DEFAULT false,
`requestDates` JSON NOT NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `_FacilityToAdmin` (
`A` INTEGER NOT NULL,
`B` INTEGER NOT NULL,

UNIQUE INDEX `_FacilityToAdmin_AB_unique`(`A`, `B`),
INDEX `_FacilityToAdmin_B_index`(`B`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `_AdminToRequest` (
`A` INTEGER NOT NULL,
`B` INTEGER NOT NULL,

UNIQUE INDEX `_AdminToRequest_AB_unique`(`A`, `B`),
INDEX `_AdminToRequest_B_index`(`B`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `_FacilityToRequest` (
`A` INTEGER NOT NULL,
`B` INTEGER NOT NULL,

UNIQUE INDEX `_FacilityToRequest_AB_unique`(`A`, `B`),
INDEX `_FacilityToRequest_B_index`(`B`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `_EquipmentToRequest` (
`A` INTEGER NOT NULL,
`B` INTEGER NOT NULL,

UNIQUE INDEX `_EquipmentToRequest_AB_unique`(`A`, `B`),
INDEX `_EquipmentToRequest_B_index`(`B`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `_StudentToRequest` (
`A` INTEGER NOT NULL,
`B` INTEGER NOT NULL,

UNIQUE INDEX `_StudentToRequest_AB_unique`(`A`, `B`),
INDEX `_StudentToRequest_B_index`(`B`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `User` ADD CONSTRAINT `User_schoolId_fkey` FOREIGN KEY (`schoolId`) REFERENCES `School`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Section` ADD CONSTRAINT `Section_schoolId_fkey` FOREIGN KEY (`schoolId`) REFERENCES `School`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Admin` ADD CONSTRAINT `Admin_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Student` ADD CONSTRAINT `Student_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Student` ADD CONSTRAINT `Student_sectionId_fkey` FOREIGN KEY (`sectionId`) REFERENCES `Section`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Facility` ADD CONSTRAINT `Facility_schoolId_fkey` FOREIGN KEY (`schoolId`) REFERENCES `School`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Equipment` ADD CONSTRAINT `Equipment_schoolId_fkey` FOREIGN KEY (`schoolId`) REFERENCES `School`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_FacilityToAdmin` ADD CONSTRAINT `_FacilityToAdmin_A_fkey` FOREIGN KEY (`A`) REFERENCES `Admin`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_FacilityToAdmin` ADD CONSTRAINT `_FacilityToAdmin_B_fkey` FOREIGN KEY (`B`) REFERENCES `Facility`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_AdminToRequest` ADD CONSTRAINT `_AdminToRequest_A_fkey` FOREIGN KEY (`A`) REFERENCES `Admin`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_AdminToRequest` ADD CONSTRAINT `_AdminToRequest_B_fkey` FOREIGN KEY (`B`) REFERENCES `Request`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_FacilityToRequest` ADD CONSTRAINT `_FacilityToRequest_A_fkey` FOREIGN KEY (`A`) REFERENCES `Facility`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_FacilityToRequest` ADD CONSTRAINT `_FacilityToRequest_B_fkey` FOREIGN KEY (`B`) REFERENCES `Request`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_EquipmentToRequest` ADD CONSTRAINT `_EquipmentToRequest_A_fkey` FOREIGN KEY (`A`) REFERENCES `Equipment`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_EquipmentToRequest` ADD CONSTRAINT `_EquipmentToRequest_B_fkey` FOREIGN KEY (`B`) REFERENCES `Request`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_StudentToRequest` ADD CONSTRAINT `_StudentToRequest_A_fkey` FOREIGN KEY (`A`) REFERENCES `Request`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_StudentToRequest` ADD CONSTRAINT `_StudentToRequest_B_fkey` FOREIGN KEY (`B`) REFERENCES `Student`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
11 changes: 11 additions & 0 deletions prisma/migrations/20240304144205_added_session_table/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- CreateTable
CREATE TABLE `Session` (
`id` VARCHAR(191) NOT NULL,
`userId` VARCHAR(191) NOT NULL,
`expiresAt` DATETIME(3) NOT NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `Session` ADD CONSTRAINT `Session_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- CreateTable
CREATE TABLE `Password` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`hashedPassword` VARCHAR(191) NOT NULL,
`userId` VARCHAR(191) NOT NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `Password` ADD CONSTRAINT `Password_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:
- You are about to drop the column `middleName` on the `user` table. All the data in the column will be lost.
- You are about to drop the column `password` on the `user` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE `user` DROP COLUMN `middleName`,
DROP COLUMN `password`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- Made the column `email` on table `user` required. This step will fail if there are existing NULL values in that column.
*/
-- AlterTable
ALTER TABLE `user` MODIFY `email` VARCHAR(191) NOT NULL;
15 changes: 15 additions & 0 deletions prisma/migrations/20240304233048_simplified_password/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Warnings:
- You are about to drop the `password` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `hashedPassword` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE `password` DROP FOREIGN KEY `Password_userId_fkey`;

-- AlterTable
ALTER TABLE `user` ADD COLUMN `hashedPassword` VARCHAR(191) NOT NULL;

-- DropTable
DROP TABLE `password`;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "mysql"
Loading

0 comments on commit 8d12cba

Please sign in to comment.