-- Tanım ve gider tablolarına pasife alma (soft delete) kolonu
-- Mevcut kayıtlar aktif kalır.
-- Kolon zaten varsa (uygulama AktifKayit::ensureColumn ile eklediyse) ilgili satır atlanır.

SET @db := DATABASE();

-- ekstra_islem_turleri.aktif
SET @exists := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'ekstra_islem_turleri' AND COLUMN_NAME = 'aktif'
);
SET @sql := IF(@exists = 0,
    'ALTER TABLE `ekstra_islem_turleri` ADD COLUMN `aktif` TINYINT(1) NOT NULL DEFAULT 1 AFTER `updated_at`',
    'SELECT ''ekstra_islem_turleri.aktif zaten mevcut'' AS bilgi'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- gider_turleri.aktif
SET @exists := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'gider_turleri' AND COLUMN_NAME = 'aktif'
);
SET @sql := IF(@exists = 0,
    'ALTER TABLE `gider_turleri` ADD COLUMN `aktif` TINYINT(1) NOT NULL DEFAULT 1 AFTER `updated_at`',
    'SELECT ''gider_turleri.aktif zaten mevcut'' AS bilgi'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- arac_markalari.aktif
SET @exists := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'arac_markalari' AND COLUMN_NAME = 'aktif'
);
SET @sql := IF(@exists = 0,
    'ALTER TABLE `arac_markalari` ADD COLUMN `aktif` TINYINT(1) NOT NULL DEFAULT 1 AFTER `updated_at`',
    'SELECT ''arac_markalari.aktif zaten mevcut'' AS bilgi'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- gider_kayitlari.aktif
SET @exists := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'gider_kayitlari' AND COLUMN_NAME = 'aktif'
);
SET @sql := IF(@exists = 0,
    'ALTER TABLE `gider_kayitlari` ADD COLUMN `aktif` TINYINT(1) NOT NULL DEFAULT 1 AFTER `created_at`',
    'SELECT ''gider_kayitlari.aktif zaten mevcut'' AS bilgi'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- whatsapp_mesaj_sablonlari.aktif
SET @exists := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'whatsapp_mesaj_sablonlari' AND COLUMN_NAME = 'aktif'
);
SET @sql := IF(@exists = 0,
    'ALTER TABLE `whatsapp_mesaj_sablonlari` ADD COLUMN `aktif` TINYINT(1) NOT NULL DEFAULT 1 AFTER `siralama`',
    'SELECT ''whatsapp_mesaj_sablonlari.aktif zaten mevcut'' AS bilgi'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
