From b7468e2a536398735ab706b694db0d29d4345d1f Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Sun, 26 Jul 2026 17:33:32 +0000 Subject: [PATCH] =?UTF-8?q?Register=20utilities=20app=20=E2=80=94=20seed?= =?UTF-8?q?=20row=20+=20capabilities?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LXC 127, 10.10.10.127:3080. Six capabilities: readings, meters, tariffs, reports, estimates, settings. No default Staff grants. Co-Authored-By: Claude Sonnet 5 --- src/db.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/db.js b/src/db.js index c582427..095145b 100644 --- a/src/db.js +++ b/src/db.js @@ -384,6 +384,40 @@ export async function initDb() { sort_order = EXCLUDED.sort_order `) + // Seed utilities app + capabilities (no default Staff grants — admin assigns via portal) + await pool.query(` + INSERT INTO apps (slug, name, description, base_path, icon, theme_color, category, internal_host, internal_port) + VALUES ('utilities', 'Utilities', 'Meter readings, tariffs and energy cost tracking', '/utilities', 'Zap', '#1e6091', 'Operations', '10.10.10.127', 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 + CROSS JOIN (VALUES + ('readings', 'Enter Readings', 'Enter manual meter readings and view reading history', 1), + ('meters', 'Manage Meters', 'Create/edit categories, meters, locations and images', 2), + ('tariffs', 'Manage Tariffs', 'Create/edit tariffs, rate windows, standing charges and CCL', 3), + ('reports', 'View Reports', 'View consumption and cost reports', 4), + ('estimates', 'View Estimates', 'View and adjust period cost estimates', 5), + ('settings', 'Settings', 'App settings', 6) + ) AS c(slug, name, description, sort_order) + WHERE a.slug = 'utilities' + ON CONFLICT (app_id, slug) DO UPDATE SET + name = EXCLUDED.name, + description = EXCLUDED.description, + sort_order = EXCLUDED.sort_order + `) + // Seed first admin user if table is empty const { rows } = await pool.query('SELECT COUNT(*) FROM users') if (parseInt(rows[0].count) === 0) {