-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmigration-google-oauth.sql
More file actions
25 lines (21 loc) · 1.03 KB
/
Copy pathmigration-google-oauth.sql
File metadata and controls
25 lines (21 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- Migration: Add Google OAuth support
-- Date: 2025-11-12
-- Modify users table to make password_hash optional for OAuth users
ALTER TABLE users ALTER COLUMN password_hash DROP NOT NULL;
-- Create oauth_accounts table to store OAuth provider information
CREATE TABLE IF NOT EXISTS oauth_accounts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
provider TEXT NOT NULL, -- 'google', 'facebook', etc.
provider_user_id TEXT NOT NULL, -- ID from the OAuth provider
email TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(provider, provider_user_id)
);
-- Create indexes for oauth_accounts
CREATE INDEX IF NOT EXISTS idx_oauth_accounts_user_id ON oauth_accounts(user_id);
CREATE INDEX IF NOT EXISTS idx_oauth_accounts_provider ON oauth_accounts(provider);
CREATE INDEX IF NOT EXISTS idx_oauth_accounts_email ON oauth_accounts(email);
-- Add comment
COMMENT ON TABLE oauth_accounts IS 'Stores OAuth provider account connections for users';