-- SPDX-License-Identifier: Apache-2.0
--
-- 0008 — tenants_index.db: add `tenants.quota_bytes` (v0.8.1 P3).
--
-- Closes the v0.8.0 known-issue gap where `solo tenants create
-- --quota-bytes <N>` accepted the flag but never persisted the value
-- and no enforcement existed.
--
-- IMPORTANT — this migration ONLY applies to `<data_dir>/tenants_index.db`.
-- The per-tenant DBs at `<data_dir>/tenants/<id>.db` continue to use
-- the per-tenant migration chain unchanged.
--
-- v0.8.0's release notes claimed `tenants.quota_bytes` existed in
-- migration 0004; an audit during v0.8.1 P3 implementation showed the
-- claim was a drift between docs and code — the column was NEVER added
-- in 0004. This migration adds it for the first time. Nullable
-- (default: unlimited / `NULL`); enforcement only runs when the column
-- has a non-NULL value, so the upgrade is behaviour-neutral for
-- existing tenants.
--
-- ## Why on tenants_index.db, not per-tenant
--
-- Quota is metadata about the tenant (lives in the registry alongside
-- `tenant_id`, `display_name`, `status`), not per-tenant data. The
-- writer-actor reads the value from tenants_index when checking quota
-- before an INSERT; per-tenant DBs don't carry their own copy. This
-- avoids the keep-in-sync hazard the brief explicitly warns against.

ALTER TABLE tenants ADD COLUMN quota_bytes INTEGER;

-- No index: `quota_bytes` is read per-write but only for the requesting
-- tenant (already an O(1) primary-key lookup on tenant_id). Adding a
-- separate index would just consume space without speeding any query.
