-- Migration: 028_drop_person_identities_table.sql
-- Date: 2026-04-28
-- Version: V4.0
-- Purpose: Remove person_identities table (V3.x → V4.0 architecture)

BEGIN;

-- 1. Backup data (optional, uncomment if needed)
-- CREATE TABLE person_identities_backup AS SELECT * FROM person_identities;

-- 2. Drop indexes
DROP INDEX IF EXISTS idx_person_identities_file_uuid;
DROP INDEX IF EXISTS idx_person_identities_file_uuid;

-- 3. Drop table
DROP TABLE IF EXISTS person_identities CASCADE;

-- 4. Drop related tables (person_appearances)
DROP TABLE IF EXISTS person_appearances CASCADE;

-- 5. Drop related functions
DROP FUNCTION IF EXISTS get_person_timeline(p_file_uuid VARCHAR);
DROP FUNCTION IF EXISTS get_person_statistics(p_file_uuid VARCHAR);
DROP FUNCTION IF EXISTS get_person_timeline_with_chunks(p_file_uuid VARCHAR);

-- 6. Drop related triggers (if exists)
DROP TRIGGER IF EXISTS update_person_appearances_trigger ON face_detections;
DROP FUNCTION IF EXISTS update_person_appearances();

COMMIT;