Files

23 lines
589 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pg from "pg";
const { Pool } = pg;
export function createPool() {
const url = process.env.DATABASE_URL;
if (!url) {
throw new Error("Не задана переменная DATABASE_URL");
}
return new Pool({ connectionString: url, max: 10 });
}
export async function migrate(pool) {
await pool.query(`
CREATE TABLE IF NOT EXISTS incidents (
number_key INTEGER PRIMARY KEY,
data JSONB NOT NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS incidents_updated_at_idx ON incidents (updated_at DESC);
`);
}