-- product_discount_offers tablosuna kampanya tarih araligi alanlari ekler.
USE faunamix;

SET @has_starts_at := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'product_discount_offers'
    AND COLUMN_NAME = 'starts_at'
);
SET @sql_starts_at := IF(@has_starts_at = 0,
  'ALTER TABLE product_discount_offers ADD COLUMN starts_at DATETIME NULL DEFAULT NULL AFTER discount_percent',
  'SELECT 1');
PREPARE stmt FROM @sql_starts_at; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @has_ends_at := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'product_discount_offers'
    AND COLUMN_NAME = 'ends_at'
);
SET @sql_ends_at := IF(@has_ends_at = 0,
  'ALTER TABLE product_discount_offers ADD COLUMN ends_at DATETIME NULL DEFAULT NULL AFTER starts_at',
  'SELECT 1');
PREPARE stmt FROM @sql_ends_at; EXECUTE stmt; DEALLOCATE PREPARE stmt;
