use anyhow::Result; use momentry_core::core::chunk::rule1_ingest; use momentry_core::core::config; use momentry_core::core::db::PostgresDb; #[tokio::main] async fn main() -> Result<()> { tracing_subscriber::fmt::init(); let db = PostgresDb::new(&config::DATABASE_URL).await?; // Find files with OCR pre_chunks but missing OCR chunks let files: Vec<(String, f64)> = sqlx::query_as::<_, (String, f64)>( r#" SELECT pc.file_uuid, v.fps FROM pre_chunks pc JOIN videos v ON v.file_uuid = pc.file_uuid WHERE pc.processor_type = 'ocr' AND NOT EXISTS ( SELECT 1 FROM chunk c WHERE c.file_uuid = pc.file_uuid AND c.chunk_type = 'ocr' ) GROUP BY pc.file_uuid, v.fps ORDER BY COUNT(*) DESC "#, ) .fetch_all(db.pool()) .await?; println!("Found {} files with OCR stuck in pre_chunks", files.len()); for (file_uuid, fps) in &files { println!("Processing {} (fps={})...", file_uuid, fps); match rule1_ingest::execute_rule1(&db, file_uuid, *fps).await { Ok(count) => println!(" ✅ Created {} chunks", count), Err(e) => eprintln!(" ❌ Failed: {}", e), } } println!("Done!"); Ok(()) }