-- sql/migrations/staging/001_customer_valkey.sql
-- Adds per-customer Valkey (Redis-compatible) cache state table.
-- See docs/superpowers/specs/2026-04-20-customer-valkey-design.md
--
-- WHP uses `username` (VARCHAR(32)) as the account identifier across tables
-- (client_allowances, sites, containers, etc.) rather than a numeric customer
-- id. We follow that convention here and rely on application-layer cleanup
-- (usermgmt.php::delete_user) for orphan removal, matching other username-
-- keyed tables like `sites` which do not enforce FKs against accounts.

CREATE TABLE IF NOT EXISTS whp.customer_valkey (
    username         VARCHAR(32) NOT NULL PRIMARY KEY,
    enabled          TINYINT(1) NOT NULL DEFAULT 0,
    memory_mb        INT NOT NULL DEFAULT 0,
    mode             ENUM('cache','snapshot') NOT NULL DEFAULT 'cache',
    eviction_policy  VARCHAR(32) NOT NULL DEFAULT 'allkeys-lru',
    version          VARCHAR(16) NOT NULL DEFAULT '8.0',
    network_name     VARCHAR(64) NOT NULL DEFAULT '',
    container_name   VARCHAR(64) NOT NULL DEFAULT '',
    created_at       TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at       TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
