nxtgauge-backend-rust/crates/db/migrations/20260415010001_create_user_role_profiles.up.sql
Tracewebstudio Dev 03376b9567 feat: Add database redesign documentation and Phase 1-2 migrations
- Add schema_audit.md documenting current schema issues
- Add target_schema.md with complete target schema design
- Add old_to_new_mapping.md with table mapping
- Add migration_plan.md with phased migration strategy
- Add Phase 1 migrations (core infrastructure):
  - user_sessions table
  - users missing columns
  - departments updates
  - designations updates
  - employees updates
- Add Phase 2 migrations (profile domain - CRITICAL):
  - create user_role_profiles root table
  - backfill user_role_profiles from existing profiles
  - add user_role_profile_id to extension tables
  - remove forbidden external portfolio links
- Add user_role_profile Rust model
- Update photographer model to use user_role_profile_id
2026-04-12 23:21:11 +02:00

31 lines
1.3 KiB
SQL

-- 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);