const { PrismaClient } = require('@prisma/client'); const prisma = new PrismaClient(); async function main() { const rows = await prisma.tenant.findMany({ select: { id: true, notes: true, appVersion: true }, }); let n = 0; for (const row of rows) { const match = String(row.notes || '').match(/version:([^|\s]+)/i); if (!match?.[1]) continue; if (row.appVersion && row.appVersion !== '1') continue; await prisma.tenant.update({ where: { id: row.id }, data: { appVersion: match[1].trim() }, }); n += 1; } console.log(`backfilled ${n} of ${rows.length}`); } main() .catch((error) => { console.error(error); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });