|
| 1 | +-- Profile Enhancements: verification, preferences, activity history |
| 2 | +-- Migration: 20260528000003_profile_enhancements.sql |
| 3 | + |
| 4 | +-- Add verification status to user_profiles |
| 5 | +ALTER TABLE user_profiles |
| 6 | +ADD COLUMN IF NOT EXISTS verification_status VARCHAR(20) NOT NULL DEFAULT 'unverified' |
| 7 | +CHECK (verification_status IN ('unverified', 'pending', 'verified', 'rejected')); |
| 8 | + |
| 9 | +-- Create user_preferences table |
| 10 | +CREATE TABLE IF NOT EXISTS user_preferences ( |
| 11 | + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), |
| 12 | + user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, |
| 13 | + preferences JSONB NOT NULL DEFAULT '{}', |
| 14 | + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), |
| 15 | + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), |
| 16 | + CONSTRAINT user_preferences_user_id_key UNIQUE (user_id) |
| 17 | +); |
| 18 | + |
| 19 | +-- Create profile_activity table |
| 20 | +CREATE TABLE IF NOT EXISTS profile_activity ( |
| 21 | + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), |
| 22 | + user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, |
| 23 | + activity_type VARCHAR(50) NOT NULL, |
| 24 | + description TEXT, |
| 25 | + metadata JSONB DEFAULT '{}', |
| 26 | + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() |
| 27 | +); |
| 28 | + |
| 29 | +-- Index for activity queries |
| 30 | +CREATE INDEX IF NOT EXISTS idx_profile_activity_user_id ON profile_activity(user_id); |
| 31 | +CREATE INDEX IF NOT EXISTS idx_profile_activity_created_at ON profile_activity(created_at DESC); |
| 32 | + |
| 33 | +-- Trigger for user_preferences updated_at |
| 34 | +CREATE OR REPLACE FUNCTION update_user_preferences_updated_at() |
| 35 | +RETURNS TRIGGER AS $$ |
| 36 | +BEGIN |
| 37 | + NEW.updated_at = NOW(); |
| 38 | + RETURN NEW; |
| 39 | +END; |
| 40 | +$$ LANGUAGE plpgsql; |
| 41 | + |
| 42 | +CREATE TRIGGER update_user_preferences_updated_at |
| 43 | + BEFORE UPDATE ON user_preferences |
| 44 | + FOR EACH ROW |
| 45 | + EXECUTE FUNCTION update_user_preferences_updated_at(); |
0 commit comments