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;
|
||||
Reference in New Issue
Block a user