// One-shot wipe of the payment_methods + payment_method_groups tables in the // current DATABASE_URL. Use when you want the seed in migrate.js to repopulate // from scratch on the next migration run. // // Safe against payment_requests because that table does NOT FK into // payment_methods — `xendit_payment_method` and `product_metadata.preferred_payment_code` // are free-text columns. // // Usage: // cd backend && node .dev/reset-payment-catalog.js // cd backend && node src/db/migrate.js import 'dotenv/config' import { getDb } from '../src/db/client.js' const sql = getDb() const [{ count: methodCount }] = await sql`SELECT COUNT(*)::int AS count FROM payment_methods` const [{ count: groupCount }] = await sql`SELECT COUNT(*)::int AS count FROM payment_method_groups` console.log(`Before: ${methodCount} methods, ${groupCount} groups`) // FK is payment_methods.group_id → payment_method_groups (ON DELETE RESTRICT), // so methods must go first. await sql`DELETE FROM payment_methods` await sql`DELETE FROM payment_method_groups` console.log('Wiped. Now run: node src/db/migrate.js') await sql.end()