-- 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) );