USE kapadokya_db;

-- Add slug column to categories if not exists
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'kapadokya_db' AND TABLE_NAME = 'categories' AND COLUMN_NAME = 'slug');
SET @sql = IF(@col_exists = 0, 'ALTER TABLE categories ADD COLUMN slug VARCHAR(300) UNIQUE AFTER title', 'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- Add slug column to destinations if not exists
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'kapadokya_db' AND TABLE_NAME = 'destinations' AND COLUMN_NAME = 'slug');
SET @sql = IF(@col_exists = 0, 'ALTER TABLE destinations ADD COLUMN slug VARCHAR(300) UNIQUE AFTER title', 'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- Populate slugs for categories
UPDATE categories SET slug = 'sicak-hava-balonu' WHERE title = 'Sıcak Hava Balonu' AND (slug IS NULL OR slug = '');
UPDATE categories SET slug = 'atv-safari' WHERE title = 'ATV Safari' AND (slug IS NULL OR slug = '');
UPDATE categories SET slug = 'magara-oteller' WHERE title = 'Mağara Oteller' AND (slug IS NULL OR slug = '');
UPDATE categories SET slug = 'gun-batimi-noktalari' WHERE title = 'Gün Batımı Noktaları' AND (slug IS NULL OR slug = '');
UPDATE categories SET slug = 'vadilerde-yuruyus' WHERE title = 'Vadilerde Yürüyüş' AND (slug IS NULL OR slug = '');
UPDATE categories SET slug = 'yeralti-sehirleri' WHERE title = 'Yeraltı Şehirleri' AND (slug IS NULL OR slug = '');
UPDATE categories SET slug = 'seramik-atolyeleri' WHERE title = 'Seramik Atölyeleri' AND (slug IS NULL OR slug = '');

-- Populate slugs for destinations
UPDATE destinations SET slug = 'goreme' WHERE title = 'Göreme' AND (slug IS NULL OR slug = '');
UPDATE destinations SET slug = 'urgup' WHERE title = 'Ürgüp' AND (slug IS NULL OR slug = '');
UPDATE destinations SET slug = 'avanos' WHERE title = 'Avanos' AND (slug IS NULL OR slug = '');
UPDATE destinations SET slug = 'uchisar' WHERE title = 'Uçhisar' AND (slug IS NULL OR slug = '');
UPDATE destinations SET slug = 'cavusin' WHERE title = 'Çavuşin' AND (slug IS NULL OR slug = '');
UPDATE destinations SET slug = 'ortahisar' WHERE title = 'Ortahisar' AND (slug IS NULL OR slug = '');
UPDATE destinations SET slug = 'mustafapasa' WHERE title = 'Mustafapaşa' AND (slug IS NULL OR slug = '');
UPDATE destinations SET slug = 'ihlara-vadisi' WHERE title = 'Ihlara Vadisi' AND (slug IS NULL OR slug = '');
UPDATE destinations SET slug = 'zelve' WHERE title = 'Zelve' AND (slug IS NULL OR slug = '');
UPDATE destinations SET slug = 'derinkuyu' WHERE title = 'Derinkuyu' AND (slug IS NULL OR slug = '');
UPDATE destinations SET slug = 'kaymakli' WHERE title = 'Kaymaklı' AND (slug IS NULL OR slug = '');
UPDATE destinations SET slug = 'soganli' WHERE title = 'Soğanlı' AND (slug IS NULL OR slug = '');
