-- =========================================================================
-- MIGRATION: Tambah Cluster (Commercial Company / Strategy Company)
-- Jalankan di phpMyAdmin > tab SQL, pada database SPMS sedia ada anda.
-- =========================================================================

-- Guna semakan information_schema supaya selamat dijalankan berulang
-- kali (idempotent) — elak ralat "#1060 - Duplicate column name
-- 'cluster'" kalau skrip ini pernah dijalankan sebelum ini.
SET @col_exists = (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'subsidiaries' AND COLUMN_NAME = 'cluster'
);
SET @ddl_sql = IF(@col_exists = 0,
    'ALTER TABLE subsidiaries ADD COLUMN cluster ENUM(''commercial'',''strategy'') NOT NULL DEFAULT ''commercial'' AFTER name',
    'SELECT ''Lajur cluster sudah wujud — langkau ALTER TABLE.'' AS info'
);
PREPARE stmt_add_cluster FROM @ddl_sql;
EXECUTE stmt_add_cluster;
DEALLOCATE PREPARE stmt_add_cluster;
