- 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
16 lines
651 B
SQL
16 lines
651 B
SQL
-- Phase 1.1: Create user_sessions table
|
|
-- Migration: 20260415000001
|
|
|
|
CREATE TABLE IF NOT EXISTS user_sessions (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
session_token TEXT UNIQUE NOT NULL,
|
|
ip_address TEXT,
|
|
user_agent TEXT,
|
|
expires_at TIMESTAMPTZ NOT NULL,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_user_sessions_user_id ON user_sessions(user_id);
|
|
CREATE INDEX IF NOT EXISTS idx_user_sessions_token ON user_sessions(session_token);
|
|
CREATE INDEX IF NOT EXISTS idx_user_sessions_expires ON user_sessions(expires_at);
|