-- Page builder: yayınlanmış ve taslak layout JSON (panel → vitrin).

SET @has_layout_draft := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'site_pages' AND COLUMN_NAME = 'layout_json_draft'
);
SET @sql_layout_draft := IF(@has_layout_draft = 0,
  'ALTER TABLE site_pages ADD COLUMN layout_json_draft JSON NULL AFTER body_html',
  'SELECT 1');
PREPARE stmt FROM @sql_layout_draft; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @has_layout_pub := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'site_pages' AND COLUMN_NAME = 'layout_json_published'
);
SET @sql_layout_pub := IF(@has_layout_pub = 0,
  'ALTER TABLE site_pages ADD COLUMN layout_json_published JSON NULL AFTER layout_json_draft',
  'SELECT 1');
PREPARE stmt FROM @sql_layout_pub; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @has_pub_at := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'site_pages' AND COLUMN_NAME = 'layout_published_at'
);
SET @sql_pub_at := IF(@has_pub_at = 0,
  'ALTER TABLE site_pages ADD COLUMN layout_published_at DATETIME NULL DEFAULT NULL AFTER layout_json_published',
  'SELECT 1');
PREPARE stmt FROM @sql_pub_at; EXECUTE stmt; DEALLOCATE PREPARE stmt;
