Spaces:
Paused
Paused
File size: 1,383 Bytes
8395368 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import { PrismaClient } from '@prisma/client';
import fs from 'fs';
const prisma = new PrismaClient();
async function main() {
console.log('Starting column check...');
try {
// 1. Check if column exists using raw SQL
const checkQuery = `
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'Product' AND column_name = 'scrapedReviews';
`;
console.log('Executing check query...');
const result = await prisma.$queryRawUnsafe(checkQuery);
if (result.length > 0) {
console.log('SUCCESS: "scrapedReviews" column ALREADY exists.');
} else {
console.log('WARNING: "scrapedReviews" column MISSING. Attempting to add it...');
// 2. Add column if missing
const alterQuery = `ALTER TABLE "Product" ADD COLUMN IF NOT EXISTS "scrapedReviews" JSONB;`;
await prisma.$executeRawUnsafe(alterQuery);
console.log('SUCCESS: executed ALTER TABLE command.');
// 3. Verify again
const verifyResult = await prisma.$queryRawUnsafe(checkQuery);
if (verifyResult.length > 0) {
console.log('VERIFICATION: Column added successfully!');
} else {
console.error('ERROR: Column still missing after ALTER TABLE.');
}
}
} catch (e) {
console.error('CRITICAL ERROR:', e);
} finally {
await prisma.$disconnect();
}
}
main();
|