// scripts/update-thumbnail-urls.ts
// Update all existing thumbnail URLs from /uploads/thumbnails/ to /api/thumbnails/

import { prisma } from "@/lib/prisma";

async function main() {
  try {
    console.log("Updating thumbnail URLs...");
    
    const result = await prisma.$executeRawUnsafe(
      `UPDATE "Video" 
       SET thumbnail = REPLACE(thumbnail, '/uploads/thumbnails/', '/api/thumbnails/') 
       WHERE thumbnail IS NOT NULL 
       AND thumbnail LIKE '/uploads/thumbnails/%'`
    );
    
    console.log(`✓ Updated ${result} video records`);
  } catch (error) {
    console.error("Error updating thumbnail URLs:", error);
    process.exit(1);
  } finally {
    await prisma.$disconnect();
  }
}

main();
