sandbox-notebookllamalm-nextjs/backend/migrate_add_sso.sql

21 lines
742 B
SQL

-- Migration: Add SSO Authentication Support
-- Run this with: PGPASSWORD=admin psql -h localhost -p 5433 -U postgres -d postgres_nextjs -f migrate_add_sso.sql
-- Add auth_provider column (defaults to 'local' for existing users)
ALTER TABLE users
ADD COLUMN IF NOT EXISTS auth_provider VARCHAR(20) DEFAULT 'local' NOT NULL;
-- Make password_hash nullable (SSO users won't have passwords)
ALTER TABLE users
ALTER COLUMN password_hash DROP NOT NULL;
-- Set all existing users to 'local' provider
UPDATE users
SET auth_provider = 'local'
WHERE auth_provider IS NULL;
-- Verify changes
SELECT id, email, username, auth_provider,
CASE WHEN password_hash IS NULL THEN 'NULL' ELSE 'SET' END as password_status
FROM users
LIMIT 5;