Skip to content
Source
Sign inSign up
samwillis/jerry
Open History to see the last commit

migrate.ts

20 lines546 Bytes

1import pg from "pg";
2import { readFile } from "node:fs/promises";
3const pool = new pg.Pool({
4 connectionString: process.env.DATABASE_URL,
5 max: 1,
6});
7const client = await pool.connect();
8try {
9 await client.query("BEGIN");
10 await client.query("SELECT pg_advisory_xact_lock(71940318)");
11 await client.query(await readFile("migrations/001_jol.sql", "utf8"));
12 await client.query("COMMIT");
13 console.log("JOL schema is ready");
14} catch (e) {
15 await client.query("ROLLBACK");
16 throw e;
17} finally {
18 client.release();
19 await pool.end();