Spaces:
Paused
Paused
Download server/fix_missing_column.js from shanshal66/chinak2: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/spaces/shanshal66/chinak2/resolve/main/server/fix_missing_column.js
- Command line
-
hf download hf://spaces/shanshal66/chinak2/server/fix_missing_column.js
-
curl -L -o fix_missing_column.js https://huggingface.co/spaces/shanshal66/chinak2/resolve/main/server/fix_missing_column.js
1.38 kB
| 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(); | |