Files
lunarfront-app/packages/backend/src/db/migrations/0026_modules.sql
Ryan Moon e346e072b8 Add module management system for enabling/disabling features
Stores can enable/disable feature modules from Settings. When disabled,
nav links are hidden and API routes return 403. Designed as the
foundation for future license-based gating (licensed + enabled flags).

Core modules (Accounts, Members, Users, Roles, Settings) are always on.

- module_config table with slug, name, description, licensed, enabled
- In-memory cache for fast per-request module checks
- requireModule middleware wraps route groups in main.ts
- Settings page Modules card with toggle switches
- Sidebar hides nav links for disabled modules
- Default modules seeded: inventory, pos, repairs, rentals, lessons,
  files, vault, email, reports
2026-03-30 06:52:27 -05:00

25 lines
1.3 KiB
SQL

-- Module configuration table for enabling/disabling feature modules
CREATE TABLE module_config (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
slug VARCHAR(50) NOT NULL UNIQUE,
name VARCHAR(100) NOT NULL,
description TEXT,
licensed BOOLEAN NOT NULL DEFAULT true,
enabled BOOLEAN NOT NULL DEFAULT false,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- Seed default modules
INSERT INTO module_config (slug, name, description, licensed, enabled) VALUES
('inventory', 'Inventory', 'Product catalog, stock tracking, and unit management', true, true),
('pos', 'Point of Sale', 'Sales transactions, cash drawer, and receipts', true, true),
('repairs', 'Repairs', 'Repair ticket management, batches, and service templates', true, true),
('rentals', 'Rentals', 'Instrument rental agreements and billing', true, false),
('lessons', 'Lessons', 'Lesson scheduling, instructor management, and billing', true, false),
('files', 'Files', 'Shared file storage with folder organization', true, true),
('vault', 'Vault', 'Encrypted password and secret manager', true, true),
('email', 'Email', 'Email campaigns, templates, and sending', true, false),
('reports', 'Reports', 'Business reports and data export', true, true);