forecasting/seed-app.js
jtricerolph 75d2c1fa9d Forecasting app: hybrid port to HNF stack
Python FastAPI ML backend kept intact; auth replaced with central hnf_session cookie verification. Frontend rebuilt on React 18 + TS + Vite with stack design system, Plotly charts retained. Shared Postgres via DATABASE_URL; schema applied on startup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-04 18:49:34 +00:00

38 lines
1.8 KiB
JavaScript

#!/usr/bin/env node
// Run from forecasting/ dir: DATABASE_URL=<auth-db-url> node seed-app.js
import pg from 'pg'
const { Pool } = pg
const pool = new Pool({ connectionString: process.env.DATABASE_URL })
await pool.query(`
INSERT INTO apps (slug, name, description, base_path, icon, theme_color, category, internal_host, internal_port)
VALUES ('forecasting', 'Forecasting', 'Revenue forecasting and reporting', '/forecasting', 'TrendingUp', '#0077b6', 'Finance', '10.10.10.113', 3080)
ON CONFLICT (slug) DO UPDATE SET
name = EXCLUDED.name,
description = EXCLUDED.description,
base_path = EXCLUDED.base_path,
icon = EXCLUDED.icon,
theme_color = EXCLUDED.theme_color,
category = EXCLUDED.category,
internal_host = EXCLUDED.internal_host,
internal_port = EXCLUDED.internal_port
`)
await pool.query(`
INSERT INTO app_capabilities (app_id, slug, name, description, sort_order)
SELECT a.id, c.slug, c.name, c.description, c.sort_order
FROM apps a, (VALUES
('view', 'View Forecasts', 'View dashboard, forecasts, and history', 1),
('view_bookability', 'View Bookability', 'View the rate / bookability matrix', 2),
('view_competitor_rates', 'View Competitors', 'View competitor rate scraping and matrix', 3),
('view_accuracy', 'View Accuracy', 'View model accuracy metrics and backtesting', 4),
('manage_sync', 'Manage Data Sync', 'Trigger Newbook / Resos data syncs manually', 5),
('settings', 'Manage Settings', 'Configure Newbook credentials and sync schedules', 6)
) AS c(slug, name, description, sort_order)
WHERE a.slug = 'forecasting'
ON CONFLICT (app_id, slug) DO NOTHING
`)
console.log('forecasting app seeded.')
await pool.end()