-- Add shared httpd / PHP-FPM container mode support
-- This migration adds:
-- 1. PHP-FPM-only container types for use with the shared Apache httpd container
-- 2. container_mode column on the sites table to toggle between standalone and shared_httpd

USE whp;

-- Add container_mode column to sites table
ALTER TABLE sites
ADD COLUMN IF NOT EXISTS container_mode ENUM('standalone','shared_httpd') NOT NULL DEFAULT 'standalone'
AFTER container_type_id;

-- Insert PHP-FPM-only container types (one per supported PHP version)
INSERT IGNORE INTO container_types
(name, description, base_image, min_cpu, min_memory, startup_env, user_variables, mount_options, listen_port, listen_port_tls, active)
VALUES
('PHP-FPM 7.4', 'PHP-FPM only (shared httpd)',
 'repo.anhonesthost.net/cloud-hosting-platform/cac-fpm:php74',
 0.10, 128,
 '{"uid": "${WHP_UID}", "user": "${WHP_USER}", "domain": "${WHP_DOMAIN}", "FPM_LISTEN": "9000", "CONTAINER_ROLE": "fpm_only"}',
 '{}',
 '{"volumes": [{"source": "${WHP_HOME}/${WHP_DOMAIN}", "target": "/home/${WHP_USER}", "type": "bind"}]}',
 9000, 0, 1),

('PHP-FPM 8.0', 'PHP-FPM only (shared httpd)',
 'repo.anhonesthost.net/cloud-hosting-platform/cac-fpm:php80',
 0.10, 128,
 '{"uid": "${WHP_UID}", "user": "${WHP_USER}", "domain": "${WHP_DOMAIN}", "FPM_LISTEN": "9000", "CONTAINER_ROLE": "fpm_only"}',
 '{}',
 '{"volumes": [{"source": "${WHP_HOME}/${WHP_DOMAIN}", "target": "/home/${WHP_USER}", "type": "bind"}]}',
 9000, 0, 1),

('PHP-FPM 8.1', 'PHP-FPM only (shared httpd)',
 'repo.anhonesthost.net/cloud-hosting-platform/cac-fpm:php81',
 0.10, 128,
 '{"uid": "${WHP_UID}", "user": "${WHP_USER}", "domain": "${WHP_DOMAIN}", "FPM_LISTEN": "9000", "CONTAINER_ROLE": "fpm_only"}',
 '{}',
 '{"volumes": [{"source": "${WHP_HOME}/${WHP_DOMAIN}", "target": "/home/${WHP_USER}", "type": "bind"}]}',
 9000, 0, 1),

('PHP-FPM 8.2', 'PHP-FPM only (shared httpd)',
 'repo.anhonesthost.net/cloud-hosting-platform/cac-fpm:php82',
 0.10, 128,
 '{"uid": "${WHP_UID}", "user": "${WHP_USER}", "domain": "${WHP_DOMAIN}", "FPM_LISTEN": "9000", "CONTAINER_ROLE": "fpm_only"}',
 '{}',
 '{"volumes": [{"source": "${WHP_HOME}/${WHP_DOMAIN}", "target": "/home/${WHP_USER}", "type": "bind"}]}',
 9000, 0, 1),

('PHP-FPM 8.3', 'PHP-FPM only (shared httpd)',
 'repo.anhonesthost.net/cloud-hosting-platform/cac-fpm:php83',
 0.10, 128,
 '{"uid": "${WHP_UID}", "user": "${WHP_USER}", "domain": "${WHP_DOMAIN}", "FPM_LISTEN": "9000", "CONTAINER_ROLE": "fpm_only"}',
 '{}',
 '{"volumes": [{"source": "${WHP_HOME}/${WHP_DOMAIN}", "target": "/home/${WHP_USER}", "type": "bind"}]}',
 9000, 0, 1),

('PHP-FPM 8.4', 'PHP-FPM only (shared httpd)',
 'repo.anhonesthost.net/cloud-hosting-platform/cac-fpm:php84',
 0.10, 128,
 '{"uid": "${WHP_UID}", "user": "${WHP_USER}", "domain": "${WHP_DOMAIN}", "FPM_LISTEN": "9000", "CONTAINER_ROLE": "fpm_only"}',
 '{}',
 '{"volumes": [{"source": "${WHP_HOME}/${WHP_DOMAIN}", "target": "/home/${WHP_USER}", "type": "bind"}]}',
 9000, 0, 1),

('PHP-FPM 8.5', 'PHP-FPM only (shared httpd)',
 'repo.anhonesthost.net/cloud-hosting-platform/cac-fpm:php85',
 0.10, 128,
 '{"uid": "${WHP_UID}", "user": "${WHP_USER}", "domain": "${WHP_DOMAIN}", "FPM_LISTEN": "9000", "CONTAINER_ROLE": "fpm_only"}',
 '{}',
 '{"volumes": [{"source": "${WHP_HOME}/${WHP_DOMAIN}", "target": "/home/${WHP_USER}", "type": "bind"}]}',
 9000, 0, 1);
