-- Migration: Add user account deletion request tracking
-- Description: Adds columns to track GDPR-compliant user account deletion requests with 30-day grace period

-- Add deletion tracking columns to user_profiles table
ALTER TABLE user_profiles
ADD COLUMN deletion_requested_at TIMESTAMP WITH TIME ZONE DEFAULT NULL,
ADD COLUMN deletion_scheduled_for TIMESTAMP WITH TIME ZONE DEFAULT NULL;

-- Create indexes for efficient purge job queries
CREATE INDEX idx_user_profiles_deletion_scheduled ON user_profiles(deletion_scheduled_for)
WHERE deletion_scheduled_for IS NOT NULL;

CREATE INDEX idx_user_profiles_deletion_requested ON user_profiles(deletion_requested_at)
WHERE deletion_requested_at IS NOT NULL;

-- Comment on columns for documentation
COMMENT ON COLUMN user_profiles.deletion_requested_at IS 'Timestamp when user requested account deletion (GDPR compliance)';
COMMENT ON COLUMN user_profiles.deletion_scheduled_for IS 'Timestamp when account will be permanently deleted (30 days after request)';
