Implemented Oauth
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "User" ADD COLUMN "OAuth_AccessToken" TEXT,
|
||||
ADD COLUMN "OAuth_RefreshToken" TEXT,
|
||||
ADD COLUMN "auth_mode" TEXT NOT NULL DEFAULT 'password';
|
||||
|
||||
-- Update existing users to have password auth mode
|
||||
UPDATE "User" SET "auth_mode" = 'password' WHERE "auth_mode" IS NULL;
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Make password optional for OAuth users
|
||||
ALTER TABLE "User" ALTER COLUMN "password" DROP NOT NULL;
|
||||
|
||||
-- Add UUID generation extension if not exists
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
-- Add default UUID generation for profileId
|
||||
ALTER TABLE "User" ALTER COLUMN "profileId" SET DEFAULT uuid_generate_v4();
|
||||
30
backend/prisma/migrations/add_google_oauth_reference.sql
Normal file
30
backend/prisma/migrations/add_google_oauth_reference.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
-- Migration: Add Google OAuth Support
|
||||
-- Description: Adds googleId field to User table and makes password optional for OAuth users
|
||||
-- Date: 2025-01-01
|
||||
|
||||
-- Step 1: Add googleId column (nullable, unique)
|
||||
ALTER TABLE "User" ADD COLUMN "googleId" TEXT;
|
||||
|
||||
-- Step 2: Make password column nullable (for OAuth users who don't have passwords)
|
||||
ALTER TABLE "User" ALTER COLUMN "password" DROP NOT NULL;
|
||||
|
||||
-- Step 3: Add unique constraint on googleId
|
||||
ALTER TABLE "User" ADD CONSTRAINT "User_googleId_key" UNIQUE ("googleId");
|
||||
|
||||
-- Step 4: Create index on googleId for faster lookups
|
||||
CREATE INDEX "User_googleId_idx" ON "User"("googleId");
|
||||
|
||||
-- Step 5: Verify existing indexes (email should already be indexed)
|
||||
-- CREATE INDEX "User_email_idx" ON "User"("email"); -- Should already exist
|
||||
|
||||
-- Notes:
|
||||
-- 1. Existing users with passwords will continue to work normally
|
||||
-- 2. New OAuth users will have NULL password and a googleId
|
||||
-- 3. Users can have both password and googleId if they link accounts
|
||||
-- 4. Email remains unique across all users (OAuth and traditional)
|
||||
|
||||
-- Rollback instructions (if needed):
|
||||
-- ALTER TABLE "User" DROP CONSTRAINT "User_googleId_key";
|
||||
-- DROP INDEX "User_googleId_idx";
|
||||
-- ALTER TABLE "User" DROP COLUMN "googleId";
|
||||
-- ALTER TABLE "User" ALTER COLUMN "password" SET NOT NULL;
|
||||
@@ -1,4 +1,3 @@
|
||||
// Generator to create Prisma Client
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
binaryTargets = ["native", "darwin-arm64", "linux-musl-arm64-openssl-3.0.x"]
|
||||
@@ -10,16 +9,71 @@ datasource db {
|
||||
relationMode = "prisma"
|
||||
}
|
||||
|
||||
enum Institute {
|
||||
KJSIDS
|
||||
SKSC
|
||||
KJSCE
|
||||
SIRC
|
||||
KJSIM
|
||||
SSA
|
||||
KJSCEd
|
||||
DLIS
|
||||
MSSMPA
|
||||
model Application {
|
||||
applicationId String @id @default(uuid())
|
||||
applicantId String
|
||||
applicant User @relation("AppliedApplications", fields: [applicantId], references: [profileId])
|
||||
institute Institute
|
||||
department String
|
||||
applicantName String
|
||||
applicationType String
|
||||
formData Json
|
||||
formName String
|
||||
resubmission Boolean @default(false)
|
||||
facultyValidation ApplicationStatus?
|
||||
hodValidation ApplicationStatus?
|
||||
hoiValidation ApplicationStatus?
|
||||
vcValidation ApplicationStatus?
|
||||
accountsValidation ApplicationStatus?
|
||||
rejectionFeedback String?
|
||||
totalExpense Float @default(0)
|
||||
proofOfTravel Bytes?
|
||||
proofOfAccommodation Bytes?
|
||||
proofOfAttendance Bytes?
|
||||
expenseProof0 Bytes?
|
||||
expenseProof1 Bytes?
|
||||
expenseProof2 Bytes?
|
||||
expenseProof3 Bytes?
|
||||
expenseProof4 Bytes?
|
||||
expenseProof5 Bytes?
|
||||
expenseProof6 Bytes?
|
||||
expenseProof7 Bytes?
|
||||
expenseProof8 Bytes?
|
||||
expenseProof9 Bytes?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
validators User[] @relation("ToValidateApplications")
|
||||
|
||||
@@index([applicantId])
|
||||
@@index([createdAt])
|
||||
}
|
||||
|
||||
model User {
|
||||
profileId String @id @default(uuid())
|
||||
userName String
|
||||
email String @unique @db.Text
|
||||
password String?
|
||||
|
||||
institute Institute?
|
||||
department String?
|
||||
designation Designation
|
||||
|
||||
appliedApplications Application[] @relation("AppliedApplications")
|
||||
toValidateApplications Application[] @relation("ToValidateApplications")
|
||||
OAuth_AccessToken String?
|
||||
OAuth_RefreshToken String?
|
||||
auth_mode String
|
||||
@@index([email])
|
||||
}
|
||||
|
||||
model ToValidateApplications {
|
||||
A String
|
||||
B String
|
||||
|
||||
@@unique([A, B], map: "_ToValidateApplications_AB_unique")
|
||||
@@index([B], map: "_ToValidateApplications_B_index")
|
||||
@@map("_ToValidateApplications")
|
||||
}
|
||||
|
||||
enum ApplicationStatus {
|
||||
@@ -37,65 +91,14 @@ enum Designation {
|
||||
STUDENT
|
||||
}
|
||||
|
||||
model User {
|
||||
profileId String @id @default(uuid())
|
||||
userName String
|
||||
email String @unique @db.Text
|
||||
password String
|
||||
|
||||
institute Institute?
|
||||
department String?
|
||||
designation Designation
|
||||
|
||||
appliedApplications Application[] @relation("AppliedApplications")
|
||||
toValidateApplications Application[] @relation("ToValidateApplications")
|
||||
|
||||
@@index([email])
|
||||
}
|
||||
|
||||
model Application {
|
||||
applicationId String @id @default(uuid())
|
||||
applicantId String
|
||||
applicant User @relation("AppliedApplications", fields: [applicantId], references: [profileId])
|
||||
institute Institute
|
||||
department String
|
||||
|
||||
applicantName String
|
||||
applicationType String
|
||||
formData Json
|
||||
|
||||
formName String
|
||||
resubmission Boolean @default(false)
|
||||
|
||||
facultyValidation ApplicationStatus?
|
||||
hodValidation ApplicationStatus?
|
||||
hoiValidation ApplicationStatus?
|
||||
vcValidation ApplicationStatus?
|
||||
accountsValidation ApplicationStatus?
|
||||
|
||||
rejectionFeedback String?
|
||||
|
||||
totalExpense Float @default(0)
|
||||
|
||||
proofOfTravel Bytes?
|
||||
proofOfAccommodation Bytes?
|
||||
proofOfAttendance Bytes?
|
||||
expenseProof0 Bytes?
|
||||
expenseProof1 Bytes?
|
||||
expenseProof2 Bytes?
|
||||
expenseProof3 Bytes?
|
||||
expenseProof4 Bytes?
|
||||
expenseProof5 Bytes?
|
||||
expenseProof6 Bytes?
|
||||
expenseProof7 Bytes?
|
||||
expenseProof8 Bytes?
|
||||
expenseProof9 Bytes?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
validators User[] @relation("ToValidateApplications")
|
||||
|
||||
@@index([applicantId])
|
||||
@@index([createdAt])
|
||||
enum Institute {
|
||||
KJSIDS
|
||||
SKSC
|
||||
KJSCE
|
||||
SIRC
|
||||
KJSIM
|
||||
SSA
|
||||
KJSCEd
|
||||
DLIS
|
||||
MSSMPA
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user