import { Pool } from 'pg'; async function syncByAddress() { 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('šŸ”„ Syncing enriched data from sail → dutchie (by address)\\n'); // Get all enriched dispensaries from sail const result = await sailPool.query(` SELECT name, address, city, state, zip, dba_name, website, phone, google_rating, google_review_count FROM azdhs_list WHERE dba_name IS NOT NULL `); console.log(`šŸ“‹ Found ${result.rows.length} enriched records in sail DB\\n`); let matched = 0; let notFound = 0; for (const disp of result.rows) { // Try to find matching record in dutchie DB by address + city const updateResult = await dutchiePool.query(` UPDATE azdhs_list SET dba_name = $1, website = $2, phone = $3, google_rating = $4, google_review_count = $5, updated_at = CURRENT_TIMESTAMP WHERE address = $6 AND city = $7 RETURNING id, name `, [ disp.dba_name, disp.website, disp.phone, disp.google_rating, disp.google_review_count, disp.address, disp.city ]); if (updateResult.rowCount > 0) { matched++; if (matched % 20 === 0) { console.log(` āœ… Matched ${matched}/${result.rows.length}...`); } } else { notFound++; console.log(` āš ļø No match: ${disp.name} at ${disp.address}, ${disp.city}`); } } console.log(`\\nšŸ“Š Results:`); console.log(` āœ… Matched and synced: ${matched}`); console.log(` āš ļø Not found in dutchie DB: ${notFound}`); } finally { await sailPool.end(); await dutchiePool.end(); } } syncByAddress().catch(console.error);