Files
tenant-registry/migrations/0031_module_users.up.sql
Sharang ParnerkarandClaude Opus 5.5 7b9ae37be7 feat(store): module user counts and sealed git admin token (0031)
Migration 0031 adds managed_services.admin_token_enc (sealed, write-only),
module_user_days (Managed Git daily counts, month = peak day) and
module_users_seen (Werkpilot/Firmwerk people per month). Postgres and
Memory stores implement both.

Refs: t81

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:28:20 +01:00

32 lines
1.4 KiB
SQL

-- Module users per tenant and month (t81). Counting only; invoicing comes
-- later with t72.
--
-- managed_services.admin_token_enc: a Gitea token with read:admin scope per
-- Managed Git instance, AES-256-GCM sealed under SECRETS_ENCRYPTION_KEY and
-- bound to the service id (like licences.llm_key_secret_enc, 0017). Write
-- only: the API never returns it.
ALTER TABLE managed_services ADD COLUMN admin_token_enc BYTEA;
-- Managed Git: one count per Berlin day (workspace members who have signed
-- in to the tenant's instance). The month's value is the peak day.
CREATE TABLE module_user_days (
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
module TEXT NOT NULL,
day DATE NOT NULL,
count INTEGER NOT NULL CHECK (count >= 0),
counted_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (tenant_id, module, day)
);
-- Werkpilot / Firmwerk: the people (Keycloak subjects) active in a Berlin
-- month. licences.last_seen_at keeps only the latest time, so the daily job
-- records them while the month runs. The month's value is the row count.
CREATE TABLE module_users_seen (
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
module TEXT NOT NULL,
month TEXT NOT NULL CHECK (month ~ '^[0-9]{4}-(0[1-9]|1[0-2])$'),
subject TEXT NOT NULL,
first_seen_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (tenant_id, module, month, subject)
);