Framework for categorised custom reports pulling from NewBook, ResOS, SambaPOS, and internal data. Report tree with collapsible categories and subcategories; date-range params; run-audit log in reports_db. Initial reports: NewBook arrivals/departures/stayovers/bookings-by-source, ResOS covers/revenue, SambaPOS sales-summary/top-products, internal run-history. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
23 lines
718 B
JavaScript
23 lines
718 B
JavaScript
import pg from 'pg'
|
|
|
|
const { Pool } = pg
|
|
export const pool = new Pool({ connectionString: process.env.DATABASE_URL })
|
|
|
|
export async function initDb() {
|
|
await pool.query(`
|
|
CREATE TABLE IF NOT EXISTS report_runs (
|
|
id SERIAL PRIMARY KEY,
|
|
report_id TEXT NOT NULL,
|
|
report_name TEXT NOT NULL,
|
|
user_email TEXT NOT NULL,
|
|
date_from DATE,
|
|
date_to DATE,
|
|
row_count INTEGER,
|
|
duration_ms INTEGER,
|
|
error TEXT,
|
|
ran_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
CREATE INDEX IF NOT EXISTS report_runs_ran_at_idx ON report_runs (ran_at DESC);
|
|
CREATE INDEX IF NOT EXISTS report_runs_report_id_idx ON report_runs (report_id);
|
|
`)
|
|
}
|