import { config } from "dotenv"; config(); import { PrismaClient } from "@prisma/client"; import { PrismaPg } from "@prisma/adapter-pg"; const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL! }); const prisma = new PrismaClient({ adapter } as any); async function main() { const dryRun = process.argv[2] !== "--apply"; const shots = await prisma.shot.findMany({ where: { shotCode: { startsWith: "UGN_" } }, select: { id: true, shotCode: true }, }); console.log(`Found ${shots.length} shot(s) with prefix UGN_`); if (shots.length === 0) return; // Show sample console.log("Sample:", JSON.stringify(shots[0])); if (dryRun) { console.log("\nDRY RUN — pass --apply to commit changes."); console.log("Would rename (first 5):"); shots.slice(0, 5).forEach((s) => { console.log(` ${s.shotCode} → UNG_${s.shotCode.slice(4)}`); }); return; } // Apply updates let updated = 0; for (const shot of shots) { const newCode = "UNG_" + shot.shotCode.slice(4); await prisma.shot.update({ where: { id: shot.id }, data: { shotCode: newCode } }); updated++; } console.log(`\nUpdated ${updated} shot(s).`); } main() .catch((e) => { console.error(e); process.exit(1); }) .finally(() => prisma.$disconnect());