-- Migration: Cleanup session_history hardware_id column
-- Date: 2025-01-03
-- Description: Migrate hardware_id data to hardware_fingerprint and remove old column

BEGIN;

-- Copy data from hardware_id to hardware_fingerprint where it's null
UPDATE session_history 
SET hardware_fingerprint = hardware_id 
WHERE hardware_fingerprint IS NULL AND hardware_id IS NOT NULL;

-- Make hardware_fingerprint NOT NULL
ALTER TABLE session_history 
ALTER COLUMN hardware_fingerprint SET NOT NULL;

-- Drop the old hardware_id column
ALTER TABLE session_history 
DROP COLUMN hardware_id CASCADE;

-- Add comment
COMMENT ON COLUMN session_history.hardware_fingerprint IS 'Unique hardware identifier for the session';

COMMIT;