-- Ustawienia automatycznego oznaczania bestsellerow per klient.

SET @sql = IF(
  EXISTS (
    SELECT 1
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'clients'
      AND COLUMN_NAME = 'bestseller_roas_entry'
  ),
  'DO 1',
  'ALTER TABLE `clients` ADD COLUMN `bestseller_roas_entry` DECIMAL(20,6) NULL DEFAULT NULL AFTER `google_ads_start_date`'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql = IF(
  EXISTS (
    SELECT 1
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'clients'
      AND COLUMN_NAME = 'bestseller_roas_exit'
  ),
  'DO 1',
  'ALTER TABLE `clients` ADD COLUMN `bestseller_roas_exit` DECIMAL(20,6) NULL DEFAULT NULL AFTER `bestseller_roas_entry`'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql = IF(
  EXISTS (
    SELECT 1
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'clients'
      AND COLUMN_NAME = 'min_conversions'
  ),
  'DO 1',
  'ALTER TABLE `clients` ADD COLUMN `min_conversions` INT(11) NOT NULL DEFAULT 10 AFTER `bestseller_roas_exit`'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql = IF(
  EXISTS (
    SELECT 1
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'clients'
      AND COLUMN_NAME = 'cooldown_period'
  ),
  'DO 1',
  'ALTER TABLE `clients` ADD COLUMN `cooldown_period` INT(11) NOT NULL DEFAULT 14 AFTER `min_conversions`'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

