fix: resolve trace-profile UPSERT SQL error and face-filter route syntax

- Fixed upsert_trace_profile() SQL: replaced scalar subqueries with LEFT JOIN
  to properly reference trace_profiles table in backfill logic
- Fixed face_filter routes: changed {file_uuid} to :file_uuid syntax for
  axum 0.7.9 compatibility
- Both fixes resolve HTTP 500 errors in rename and 404 errors in face filter
- Verified both APIs working correctly with test requests
This commit is contained in:
Accusys
2026-08-10 00:04:15 +08:00
parent d6f45683a0
commit 65da4b451a
3 changed files with 299 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
-- Migration: Populate face_filter_features from face_detections
-- This script migrates existing face detection data to the new face_filter_features table
-- Step 1: Insert data from face_detections
INSERT INTO face_filter_features (
face_id,
file_uuid,
frame,
bbox_size,
apple_vision_confidence,
primary_source,
created_at
)
SELECT
-- Generate unique face_id
CONCAT(file_uuid, '_frame', frame_number, '_face', ROW_NUMBER() OVER (PARTITION BY file_uuid, frame_number ORDER BY id)) AS face_id,
file_uuid,
frame_number AS frame,
-- Calculate bbox_size as min(width, height)
LEAST(width, height) AS bbox_size,
confidence AS apple_vision_confidence,
'apple_vision' AS primary_source,
CURRENT_TIMESTAMP AS created_at
FROM face_detections
ON CONFLICT (file_uuid, face_id) DO UPDATE SET
bbox_size = EXCLUDED.bbox_size,
apple_vision_confidence = EXCLUDED.apple_vision_confidence,
primary_source = EXCLUDED.primary_source,
created_at = EXCLUDED.created_at;
-- Step 2: Verify migration
DO $$
DECLARE
v_count BIGINT;
BEGIN
SELECT COUNT(*) INTO v_count FROM face_filter_features;
RAISE NOTICE 'Migration complete. Total faces in face_filter_features: %', v_count;
END $$;
-- Step 3: Analyze table for query optimization
ANALYZE face_filter_features;