igcrmapi/scratch/fix-db-raw.js

27 lines
929 B
JavaScript

const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function main() {
console.log('Running raw SQL to fix statuses...');
try {
// Fix empty strings
const res1 = await prisma.$executeRawUnsafe("UPDATE Client SET status = 'LEAD' WHERE status = ''");
console.log('Fixed empty statuses:', res1);
// Fix 'CUSTOMER' if it exists (mapping it to SALES)
const res2 = await prisma.$executeRawUnsafe("UPDATE Client SET status = 'SALES' WHERE status = 'CUSTOMER'");
console.log('Fixed CUSTOMER statuses:', res2);
// Also check Opportunity stages
const res3 = await prisma.$executeRawUnsafe("UPDATE Opportunity SET stage = 'LEAD' WHERE stage = ''");
console.log('Fixed empty Opportunity stages:', res3);
} catch (e) {
console.error(e);
} finally {
await prisma.$disconnect();
}
}
main();