-- Eski kurulumlar: products tablosunda fiyat/stok yoksa ekler. Yeni schema.sql ile çakışmaz.
USE faunamix;

SET @has_pt := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'products' AND COLUMN_NAME = 'price_try'
);
SET @sql_pt := IF(@has_pt = 0,
  'ALTER TABLE products ADD COLUMN price_try DECIMAL(12, 2) NOT NULL DEFAULT 0 AFTER category_slug',
  'SELECT 1');
PREPARE stmt FROM @sql_pt; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @has_sq := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'products' AND COLUMN_NAME = 'stock_quantity'
);
SET @sql_sq := IF(@has_sq = 0,
  'ALTER TABLE products ADD COLUMN stock_quantity INT UNSIGNED NOT NULL DEFAULT 0 AFTER price_try',
  'SELECT 1');
PREPARE stmt FROM @sql_sq; EXECUTE stmt; DEALLOCATE PREPARE stmt;
