Feature: API PostgreSQL — upsert по «Название», загрузка из БД при открытии

Made-with: Cursor
This commit is contained in:
cursor-agent
2026-04-06 08:59:29 +00:00
parent 5c0028c308
commit f506563cdb
11 changed files with 1272 additions and 28 deletions

22
server/db.js Normal file
View File

@@ -0,0 +1,22 @@
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);
`);
}