-- Phase 2.1: Create user_role_profiles root table (CRITICAL) -- Migration: 20260415010001 -- This is the ROOT table for all user role profiles CREATE TABLE IF NOT EXISTS user_role_profiles ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, role_key VARCHAR(50) NOT NULL, display_name TEXT, bio TEXT, location TEXT, avatar_url TEXT, phone TEXT, email TEXT, status VARCHAR(50) NOT NULL DEFAULT 'ACTIVE', verification_status VARCHAR(50) DEFAULT 'PENDING', approval_status VARCHAR(50) DEFAULT 'PENDING', rejection_reason TEXT, approved_at TIMESTAMPTZ, verified_at TIMESTAMPTZ, is_profile_public BOOLEAN DEFAULT true, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), UNIQUE(user_id, role_key) ); CREATE INDEX IF NOT EXISTS idx_user_role_profiles_user_id ON user_role_profiles(user_id); CREATE INDEX IF NOT EXISTS idx_user_role_profiles_role_key ON user_role_profiles(role_key); CREATE INDEX IF NOT EXISTS idx_user_role_profiles_status ON user_role_profiles(status); CREATE INDEX IF NOT EXISTS idx_user_role_profiles_verification ON user_role_profiles(verification_status); CREATE INDEX IF NOT EXISTS idx_user_role_profiles_approval ON user_role_profiles(approval_status);