cc00a439bf
Add a dedicated Deep Research view with postal-area preview overlays, batch execution, and bundled map results. Also add postal dataset import tooling and fix local API networking and research insert issues needed to support the new workflow.
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
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();
|