← back to Gracie Internal
scripts/export-jsonl.js
26 lines
#!/usr/bin/env node
/* Export full gracie_catalog (every column load() consumes) LOCAL dw_unified ->
data/gracie.jsonl, one raw pg row per line. Local read, $0. Row shape matches
pg output so server.js load() maps it unchanged in jsonl mode. */
const fs = require('fs');
const path = require('path');
const { Client } = require('pg');
const PG = process.env.PG || 'postgresql://localhost/dw_unified';
const OUT = path.join(__dirname, '..', 'data', 'gracie.jsonl');
(async () => {
const c = new Client({ connectionString: PG });
await c.connect();
const { rows } = await c.query(`
SELECT mfr_sku, pattern_name, color_name, collection, product_type, material,
description, ai_description, image_url, all_images, product_url,
color_hex, dominant_color_hex, ai_styles, ai_tags, ai_colors,
settlement_flag, on_shopify, dw_sku, crawled_at, last_scraped, ai_accepted_at
FROM gracie_catalog ORDER BY collection, pattern_name`);
await c.end();
fs.mkdirSync(path.dirname(OUT), { recursive: true });
fs.writeFileSync(OUT, rows.map((r) => JSON.stringify(r)).join('\n') + '\n');
console.log(`[gracie export] wrote ${rows.length} rows -> ${OUT}`);
})().catch((e) => { console.error('export failed:', e); process.exit(1); });