-- Per-site override for php-fpm's pm.max_children, applied at container
-- creation as the FPM_MAX_CHILDREN environment variable. NULL means
-- "use the cac-fpm image's calculated default" (PHP_BUDGET_MB /
-- PHP_WORKER_ESTIMATE_MB; see detect-memory.sh in cloud-apache-container).
--
-- Why: the image's worker-RSS estimate is a one-size-fits-all baseline.
-- Plugin-heavy WordPress / WooCommerce sites measure significantly higher
-- per-worker RSS, so the calculated pm.max_children can put peak demand
-- over the container memory cap. This column lets operators pin a smaller
-- value per site without forking the image or hot-patching pool configs
-- (the latter is volatile across container recreates).
--
-- Applies only when the site's container_type uses a PHP/PHP-FPM image
-- (whp.container_types.base_image matches `(cac|cac-fpm):php<n>`); ignored
-- on Node and static-Apache sites. Enforcement of that scoping lives in
-- web-files/libs/site-pool-env.php so the column itself can be set without
-- worrying about container-type drift.

ALTER TABLE whp.sites
  ADD COLUMN IF NOT EXISTS fpm_max_children_override INT NULL DEFAULT NULL
    COMMENT 'Per-site override for php-fpm pm.max_children (env FPM_MAX_CHILDREN). NULL = formula default.'
    AFTER memory_per_container;
