Public Access
1
0
Files
leads4less/db/scripts/build-postal-neighbors.ts
T
pguerrerox cc00a439bf feat: add deep research planning and postal batch runs
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.
2026-04-05 18:05:04 +00:00

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();