Ship Pokemon and Lorcana bulk import libs/scripts, unified weekly cron sync across MTG/Pokemon/Lorcana with per-game error isolation and catalog_sync_log telemetry. Admin UI adds Unified/Incremental/Bulk MTG modes. - Rename reconcile migrations to 1781442330* timestamps so they apply after bulk-data migrations without node-pg-migrate ordering conflicts - Add Lorcana set-code normalization + orphan cleanup migrations - Drop stricter user_cards_user_card_unique (keep 3-column foil unique) - Update docs/SCHEMA_MAP.md for tags, card_tags, catalog_sync_log, bulk columns Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
/**
|
|
* Bulk import all Pokémon cards from pokemon-tcg-data GitHub JSON.
|
|
*
|
|
* Fetches sets/en.json, then upserts every card in each set (keyed on scryfall_id).
|
|
* Populates legalities from set metadata where available.
|
|
*
|
|
* Usage:
|
|
* POSTGRES_URL=<url> node scripts/bulk-import-pokemon.js
|
|
* node --env-file=.env.local scripts/bulk-import-pokemon.js
|
|
*
|
|
* Options (env vars):
|
|
* BATCH_SIZE — rows per INSERT batch (default 100)
|
|
* DRY_RUN — "true" to fetch and count without writing to DB
|
|
*/
|
|
|
|
import { neon } from '@neondatabase/serverless';
|
|
|
|
import { runBulkPokemonSync } from '../lib/card-import/pokemon-bulk.js';
|
|
|
|
if (!process.env.POSTGRES_URL) {
|
|
console.error('POSTGRES_URL is required');
|
|
process.exit(1);
|
|
}
|
|
|
|
const sql = neon(process.env.POSTGRES_URL, { fullResults: false });
|
|
|
|
const BATCH_SIZE = parseInt(process.env.BATCH_SIZE || '100', 10);
|
|
const DRY_RUN = process.env.DRY_RUN === 'true';
|
|
|
|
async function run() {
|
|
console.log(
|
|
`[bulk-import-pokemon] Starting (batch=${BATCH_SIZE}, dryRun=${DRY_RUN})`
|
|
);
|
|
|
|
const summary = await runBulkPokemonSync({
|
|
batchSize: BATCH_SIZE,
|
|
dryRun: DRY_RUN,
|
|
query: (query, values) => sql.query(query, values),
|
|
});
|
|
|
|
console.log('[bulk-import-pokemon] Complete!');
|
|
console.log(`[bulk-import-pokemon] Sets processed: ${summary.setsProcessed}/${summary.totalSets}`);
|
|
console.log(`[bulk-import-pokemon] Upserted: ${summary.upserted}`);
|
|
console.log(`[bulk-import-pokemon] Skipped (dry run): ${summary.skipped}`);
|
|
console.log(`[bulk-import-pokemon] Errors: ${summary.errors}`);
|
|
}
|
|
|
|
run().catch((err) => {
|
|
console.error('[bulk-import-pokemon] Fatal error:', err);
|
|
process.exit(1);
|
|
});
|