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); `); }