-- =============================================================================
-- 00b-cpanel-helpers.sql
-- Run ONCE before other scripts (after 00-preflight, before 01).
--
-- phpMyAdmin: set the "Delimiter" box (below SQL input) to:  $$
-- Then paste this entire file and click Go.
-- After it succeeds, set Delimiter back to ; (semicolon)
--
-- Installs cp_safe_exec — runs ALTER statements and ignores
-- "already exists" errors (duplicate column / duplicate FK).
-- No information_schema access required.
-- =============================================================================

DELIMITER $$

DROP PROCEDURE IF EXISTS `cp_safe_exec`$$

CREATE PROCEDURE `cp_safe_exec`(IN p_sql TEXT)
BEGIN
  DECLARE CONTINUE HANDLER FOR 1060, 1005, 1022, 1061, 1826, 1832 BEGIN END;
  SET @cp_dynamic_sql = p_sql;
  PREPARE cp_stmt FROM @cp_dynamic_sql;
  EXECUTE cp_stmt;
  DEALLOCATE PREPARE cp_stmt;
END$$

DELIMITER ;

SELECT 'cp_safe_exec installed' AS status;
