-- Migration: 025_rename_video_uuid_to_file_uuid.sql
-- Date: 2026-04-28
-- Version: V4.0
-- Purpose: Rename video_uuid to file_uuid for terminology consistency
-- Note: Adapted to actual dev schema structure

BEGIN;

-- 1. face_detections
ALTER TABLE face_detections 
RENAME COLUMN video_uuid TO file_uuid;

DROP INDEX IF EXISTS idx_face_detections_video_uuid;
CREATE INDEX IF NOT EXISTS idx_face_detections_file_uuid ON face_detections(file_uuid);

-- 2. face_clusters
ALTER TABLE face_clusters 
RENAME COLUMN video_uuid TO file_uuid;

DROP INDEX IF EXISTS idx_face_clusters_video_uuid;
CREATE INDEX IF NOT EXISTS idx_face_clusters_file_uuid ON face_clusters(file_uuid);

-- 3. person_identities
ALTER TABLE person_identities 
RENAME COLUMN video_uuid TO file_uuid;

DROP INDEX IF EXISTS idx_person_identities_video_uuid;
CREATE INDEX IF NOT EXISTS idx_person_identities_file_uuid ON person_identities(file_uuid);

-- 4. person_appearances
ALTER TABLE person_appearances 
RENAME COLUMN video_uuid TO file_uuid;

DROP INDEX IF EXISTS idx_person_appearances_video_uuid;
CREATE INDEX IF NOT EXISTS idx_person_appearances_file_uuid ON person_appearances(file_uuid);

-- 5. chunks (check if video_uuid exists)
DO $$ 
BEGIN
    IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'chunks' AND column_name = 'video_uuid') THEN
        ALTER TABLE chunks RENAME COLUMN video_uuid TO file_uuid;
    END IF;
END $$;

COMMIT;