31 lines
902 B
SQL
31 lines
902 B
SQL
-- Add auth_provider column to users table
|
|
-- This tracks whether the user is local or uses OAuth (google, microsoft, etc.)
|
|
|
|
-- Add the column if it doesn't exist
|
|
DO $$
|
|
BEGIN
|
|
IF NOT EXISTS (
|
|
SELECT 1
|
|
FROM information_schema.columns
|
|
WHERE table_name='users' AND column_name='auth_provider'
|
|
) THEN
|
|
ALTER TABLE users ADD COLUMN auth_provider VARCHAR(50) DEFAULT 'local' NOT NULL;
|
|
END IF;
|
|
END $$;
|
|
|
|
-- Update existing users to have 'local' as their auth_provider
|
|
UPDATE users SET auth_provider = 'local' WHERE auth_provider IS NULL;
|
|
|
|
-- Create index for faster lookups
|
|
CREATE INDEX IF NOT EXISTS idx_users_auth_provider ON users(auth_provider);
|
|
|
|
-- Display the updated users table structure
|
|
SELECT
|
|
column_name,
|
|
data_type,
|
|
is_nullable,
|
|
column_default
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'users'
|
|
ORDER BY ordinal_position;
|