-- Single-row cache for the Server Admin disk-usage page.
--
-- The snapshot is taken every 6h by cron + on-demand from the page's
-- Refresh button. We always UPDATE the same row (id=1) so reads are
-- O(1) and there is no row-pruning to manage.

USE whp;

CREATE TABLE IF NOT EXISTS disk_usage_snapshot (
    id          INT NOT NULL DEFAULT 1 PRIMARY KEY,
    snapshot_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    duration_ms INT UNSIGNED DEFAULT 0,
    payload     LONGTEXT NOT NULL CHECK (json_valid(payload))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
