import { getDbPool } from '../../server/src/db/pool.js'; async function run() { const pool = getDbPool(); const client = await pool.connect(); try { await client.query('begin'); await client.query('truncate table public.postal_area_neighbors'); await client.query(` insert into public.postal_area_neighbors (postal_area_id, neighbor_postal_area_id) select source.id, neighbor.id from public.postal_areas source join public.postal_areas neighbor on source.country_code = neighbor.country_code and source.id <> neighbor.id and ST_Touches(source.geom, neighbor.geom) `); await client.query('commit'); const summary = await client.query<{ count: string }>('select count(*)::text as count from public.postal_area_neighbors'); console.log(`Built ${summary.rows[0]?.count ?? '0'} postal adjacency links.`); } catch (error) { await client.query('rollback'); throw error; } finally { client.release(); await pool.end(); } } await run();