import { Pool } from 'pg'; async function migrateProxyLocations() { const sailPool = new Pool({ connectionString: 'postgresql://sail:password@localhost:5432/dutchie_menus' }); const dutchiePool = new Pool({ connectionString: 'postgresql://dutchie:dutchie_local_pass@localhost:54320/dutchie_menus' }); try { console.log('šŸ”„ Migrating proxy location data from SAIL → DUTCHIE\n'); // Get all proxies with location data from SAIL const result = await sailPool.query(` SELECT host, port, city, state, country, country_code, active FROM proxies WHERE city IS NOT NULL ORDER BY host, port `); console.log(`šŸ“‹ Found ${result.rows.length} proxies with location data in SAIL\n`); let updated = 0; let notFound = 0; for (const proxy of result.rows) { // Update matching proxy in DUTCHIE database const updateResult = await dutchiePool.query(` UPDATE proxies SET city = $1, state = $2, country = $3, country_code = $4, active = $5 WHERE host = $6 AND port = $7 RETURNING id `, [ proxy.city, proxy.state, proxy.country, proxy.country_code, proxy.active, proxy.host, proxy.port ]); if (updateResult.rowCount > 0) { updated++; if (updated % 100 === 0) { console.log(` āœ… Updated ${updated}/${result.rows.length}...`); } } else { notFound++; console.log(` āš ļø Proxy not found in DUTCHIE: ${proxy.host}:${proxy.port}`); } } console.log(`\nšŸ“Š Results:`); console.log(` āœ… Updated: ${updated}`); console.log(` āš ļø Not found: ${notFound}`); // Verify final counts const dutchieCheck = await dutchiePool.query(` SELECT COUNT(*) as total, COUNT(*) FILTER (WHERE city IS NOT NULL) as with_location FROM proxies `); console.log(`\nāœ… DUTCHIE database now has:`); console.log(` Total proxies: ${dutchieCheck.rows[0].total}`); console.log(` With location data: ${dutchieCheck.rows[0].with_location}`); } finally { await sailPool.end(); await dutchiePool.end(); } } migrateProxyLocations().catch(console.error);