Skip to content
Source
Sign inSign up
samwillis/hackernews-realtime
Open History to see the last commit

setup.ts

23 lines528 Bytes

1import { migrate } from "../ingest/migrate";
2import { Pool } from "pg";
3const pool = new Pool({
4 connectionString:
5 process.env.DATABASE_URL_UNPOOLED || process.env.DATABASE_URL,
6 max: 1,
7});
8try {
9 const client = await pool.connect();
10 try {
11 await client.query("BEGIN");
12 await migrate(client);
13 await client.query("COMMIT");
14 console.log("HN schema ready.");
15 } catch (error) {
16 await client.query("ROLLBACK");
17 throw error;
18 } finally {
19 client.release();
20 }
21} finally {
22 await pool.end();