forked from CSI-KJSCE/Travel-policy-
31 lines
1.3 KiB
SQL
31 lines
1.3 KiB
SQL
-- 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;
|