← back to Crezana Internal

scripts/export-jsonl.js

24 lines

#!/usr/bin/env node
/* Export full crezana_catalog (every column the API serves) LOCAL dw_unified ->
   data/crezana.jsonl, one raw pg row per line. Local read, $0. Row shape matches
   pg output so server.js serves it unchanged in jsonl mode. */
const fs = require('fs');
const path = require('path');
const { Pool } = require('pg');

const pool = new Pool({ host: process.env.PGHOST || '/tmp', database: 'dw_unified' });
const OUT = path.join(__dirname, '..', 'data', 'crezana.jsonl');

(async () => {
  const { rows } = await pool.query(`
    SELECT id, dw_sku, mfr_sku, pattern_name, color_name, collection, product_type,
           image_url, product_url, description, color_hex, dominant_color_hex,
           ai_colors, ai_styles, ai_tags, crawled_at, last_scraped
    FROM crezana_catalog
    ORDER BY id`);
  await pool.end();
  fs.mkdirSync(path.dirname(OUT), { recursive: true });
  fs.writeFileSync(OUT, rows.map((r) => JSON.stringify(r)).join('\n') + '\n');
  console.log(`[crezana export] wrote ${rows.length} rows -> ${OUT}`);
})().catch((e) => { console.error('export failed:', e); process.exit(1); });