Register utilities app — seed row + capabilities

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 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-26 17:33:32 +00:00
parent 0b0a52dd33
commit b7468e2a53

View file

@ -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) {