wulf-pulse/migrations/082_company_scope.sql

26 lines
1.2 KiB
MySQL
Raw Permalink Normal View History

-- =============================================================================
-- Company scope table
-- =============================================================================
-- Controls which companies are included in Wulf's own analytics (dashboard
-- KPIs, analyzer ticket views, etc.). Opt-out model: companies without a row
-- here are implicitly in scope. Only rows with in_scope=false are excluded.
--
-- Use case: white-label / subcontract clients (TTG, LEC, PER, VCF, TNT Pizza,
-- Trivium Packaging, etc.) have dedicated branded queues and should not pollute
-- Wulf recurring-revenue metrics. Mark them in_scope=false via /admin/client-scope.
-- =============================================================================
CREATE TABLE IF NOT EXISTS company_scope (
company_id BIGINT PRIMARY KEY REFERENCES companies(id) ON DELETE CASCADE,
in_scope BOOLEAN NOT NULL DEFAULT true,
updated_by TEXT,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_company_scope_in_scope
ON company_scope(in_scope)
WHERE in_scope = false;
COMMENT ON TABLE company_scope IS
'Opt-out scope filter for analytics. Absent row = in scope. in_scope=false = excluded from dashboard KPIs and ticket views.';