-- ASAMA 77 - MEGA MENU FOUNDATION
-- Bu dosya sadece oneridir.
-- Bu oturumda calistirilmadi.
-- Hedef: menu_items tablosuna mega menu foundation kolonlarini guvenli sekilde eklemek.

SET @table_schema := DATABASE();

SET @sql := IF(
    EXISTS(
        SELECT 1
        FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @table_schema
          AND TABLE_NAME = 'menu_items'
          AND COLUMN_NAME = 'menu_type'
    ),
    'SELECT 1',
    "ALTER TABLE menu_items ADD COLUMN menu_type VARCHAR(20) NOT NULL DEFAULT 'normal' AFTER status"
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
    EXISTS(
        SELECT 1
        FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @table_schema
          AND TABLE_NAME = 'menu_items'
          AND COLUMN_NAME = 'mega_columns'
    ),
    'SELECT 1',
    "ALTER TABLE menu_items ADD COLUMN mega_columns TINYINT UNSIGNED NOT NULL DEFAULT 3 AFTER menu_type"
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
    EXISTS(
        SELECT 1
        FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @table_schema
          AND TABLE_NAME = 'menu_items'
          AND COLUMN_NAME = 'mega_width'
    ),
    'SELECT 1',
    "ALTER TABLE menu_items ADD COLUMN mega_width VARCHAR(20) NOT NULL DEFAULT 'container' AFTER mega_columns"
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
    EXISTS(
        SELECT 1
        FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @table_schema
          AND TABLE_NAME = 'menu_items'
          AND COLUMN_NAME = 'mega_background_color'
    ),
    'SELECT 1',
    "ALTER TABLE menu_items ADD COLUMN mega_background_color VARCHAR(50) NULL DEFAULT NULL AFTER mega_width"
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
    EXISTS(
        SELECT 1
        FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @table_schema
          AND TABLE_NAME = 'menu_items'
          AND COLUMN_NAME = 'mega_text_color'
    ),
    'SELECT 1',
    "ALTER TABLE menu_items ADD COLUMN mega_text_color VARCHAR(50) NULL DEFAULT NULL AFTER mega_background_color"
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
    EXISTS(
        SELECT 1
        FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @table_schema
          AND TABLE_NAME = 'menu_items'
          AND COLUMN_NAME = 'mega_show_icons'
    ),
    'SELECT 1',
    "ALTER TABLE menu_items ADD COLUMN mega_show_icons TINYINT(1) NOT NULL DEFAULT 0 AFTER mega_text_color"
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql := IF(
    EXISTS(
        SELECT 1
        FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @table_schema
          AND TABLE_NAME = 'menu_items'
          AND COLUMN_NAME = 'mega_show_descriptions'
    ),
    'SELECT 1',
    "ALTER TABLE menu_items ADD COLUMN mega_show_descriptions TINYINT(1) NOT NULL DEFAULT 0 AFTER mega_show_icons"
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- Not:
-- 1. MySQL/MariaDB surumune gore PREPARE/EXECUTE destegi gerekir.
-- 2. Calistirmadan once yedek alin.
-- 3. Bu dosya bu asamada otomatik uygulanmadi.
