-- ============================================================================
-- Gmind Institute - Database Fix Script (SIMPLE - No Stored Procedures)
-- ============================================================================
-- Run this in phpMyAdmin. If you get "Duplicate column name" error for any
-- statement, that column already exists - just skip that one and continue.
-- ============================================================================

-- 1. GALLERY TABLE - Add missing columns
ALTER TABLE `gallery` ADD COLUMN `title` VARCHAR(255) NOT NULL DEFAULT 'Gallery Image' AFTER `id`;
ALTER TABLE `gallery` ADD COLUMN `category` VARCHAR(100) DEFAULT NULL AFTER `title`;
ALTER TABLE `gallery` ADD COLUMN `description` TEXT DEFAULT NULL AFTER `category`;
ALTER TABLE `gallery` ADD COLUMN `image` VARCHAR(500) DEFAULT NULL AFTER `description`;
ALTER TABLE `gallery` ADD COLUMN `sort_order` INT NOT NULL DEFAULT 0 AFTER `image`;
ALTER TABLE `gallery` ADD COLUMN `active` TINYINT(1) NOT NULL DEFAULT 1 AFTER `sort_order`;
ALTER TABLE `gallery` ADD COLUMN `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER `active`;
ALTER TABLE `gallery` ADD COLUMN `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `created_at`;

-- 2. BRANCHES TABLE - Add missing columns
ALTER TABLE `branches` ADD COLUMN `name` VARCHAR(255) NOT NULL DEFAULT 'Branch' AFTER `id`;
ALTER TABLE `branches` ADD COLUMN `city` VARCHAR(100) NOT NULL DEFAULT '' AFTER `name`;
ALTER TABLE `branches` ADD COLUMN `state` VARCHAR(100) NOT NULL DEFAULT '' AFTER `city`;
ALTER TABLE `branches` ADD COLUMN `address` VARCHAR(500) NOT NULL DEFAULT '' AFTER `state`;
ALTER TABLE `branches` ADD COLUMN `phone` VARCHAR(20) DEFAULT NULL AFTER `address`;
ALTER TABLE `branches` ADD COLUMN `map_link` VARCHAR(500) DEFAULT NULL AFTER `phone`;
ALTER TABLE `branches` ADD COLUMN `image` VARCHAR(500) DEFAULT NULL AFTER `map_link`;
ALTER TABLE `branches` ADD COLUMN `active` TINYINT(1) NOT NULL DEFAULT 1 AFTER `image`;
ALTER TABLE `branches` ADD COLUMN `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER `active`;

-- 3. TOPPERS TABLE - Add missing columns
ALTER TABLE `toppers` ADD COLUMN `name` VARCHAR(255) NOT NULL DEFAULT 'Student' AFTER `id`;
ALTER TABLE `toppers` ADD COLUMN `course_id` INT UNSIGNED DEFAULT NULL AFTER `name`;
ALTER TABLE `toppers` ADD COLUMN `marks` VARCHAR(50) DEFAULT NULL AFTER `course_id`;
ALTER TABLE `toppers` ADD COLUMN `grade` VARCHAR(50) DEFAULT NULL AFTER `marks`;
ALTER TABLE `toppers` ADD COLUMN `photo` VARCHAR(500) DEFAULT NULL AFTER `grade`;
ALTER TABLE `toppers` ADD COLUMN `batch_year` VARCHAR(10) DEFAULT NULL AFTER `photo`;
ALTER TABLE `toppers` ADD COLUMN `branch_id` INT UNSIGNED DEFAULT NULL AFTER `batch_year`;
ALTER TABLE `toppers` ADD COLUMN `sort_order` INT NOT NULL DEFAULT 0 AFTER `branch_id`;
ALTER TABLE `toppers` ADD COLUMN `active` TINYINT(1) NOT NULL DEFAULT 1 AFTER `sort_order`;
ALTER TABLE `toppers` ADD COLUMN `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER `active`;

-- 4. COURSES TABLE - Add missing columns
ALTER TABLE `courses` ADD COLUMN `name` VARCHAR(255) NOT NULL DEFAULT 'Course' AFTER `id`;
ALTER TABLE `courses` ADD COLUMN `category` VARCHAR(100) DEFAULT 'computer' AFTER `name`;
ALTER TABLE `courses` ADD COLUMN `duration` VARCHAR(100) DEFAULT NULL AFTER `category`;
ALTER TABLE `courses` ADD COLUMN `fee` DECIMAL(10,2) DEFAULT NULL AFTER `duration`;
ALTER TABLE `courses` ADD COLUMN `description` TEXT DEFAULT NULL AFTER `fee`;
ALTER TABLE `courses` ADD COLUMN `image` VARCHAR(500) DEFAULT NULL AFTER `description`;
ALTER TABLE `courses` ADD COLUMN `syllabus` TEXT DEFAULT NULL AFTER `image`;
ALTER TABLE `courses` ADD COLUMN `featured` TINYINT(1) NOT NULL DEFAULT 0 AFTER `syllabus`;
ALTER TABLE `courses` ADD COLUMN `active` TINYINT(1) NOT NULL DEFAULT 1 AFTER `featured`;
ALTER TABLE `courses` ADD COLUMN `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER `active`;
ALTER TABLE `courses` ADD COLUMN `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `created_at`;

-- 5. SLIDERS TABLE - Add missing columns
ALTER TABLE `sliders` ADD COLUMN `title` VARCHAR(255) NOT NULL DEFAULT 'Welcome to Gmind Institute' AFTER `id`;
ALTER TABLE `sliders` ADD COLUMN `subtitle` TEXT DEFAULT NULL AFTER `title`;
ALTER TABLE `sliders` ADD COLUMN `image` VARCHAR(500) DEFAULT NULL AFTER `subtitle`;
ALTER TABLE `sliders` ADD COLUMN `button_text` VARCHAR(100) DEFAULT NULL AFTER `image`;
ALTER TABLE `sliders` ADD COLUMN `button_link` VARCHAR(500) DEFAULT NULL AFTER `button_text`;
ALTER TABLE `sliders` ADD COLUMN `sort_order` INT NOT NULL DEFAULT 0 AFTER `button_link`;
ALTER TABLE `sliders` ADD COLUMN `active` TINYINT(1) NOT NULL DEFAULT 1 AFTER `sort_order`;
ALTER TABLE `sliders` ADD COLUMN `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER `active`;

-- 6. TESTIMONIALS TABLE - Add missing columns
ALTER TABLE `testimonials` ADD COLUMN `name` VARCHAR(255) NOT NULL DEFAULT 'Student' AFTER `id`;
ALTER TABLE `testimonials` ADD COLUMN `course_name` VARCHAR(255) DEFAULT NULL AFTER `name`;
ALTER TABLE `testimonials` ADD COLUMN `review` TEXT DEFAULT NULL AFTER `course_name`;
ALTER TABLE `testimonials` ADD COLUMN `rating` TINYINT UNSIGNED NOT NULL DEFAULT 5 AFTER `review`;
ALTER TABLE `testimonials` ADD COLUMN `photo` VARCHAR(500) DEFAULT NULL AFTER `rating`;
ALTER TABLE `testimonials` ADD COLUMN `approved` TINYINT(1) NOT NULL DEFAULT 0 AFTER `photo`;
ALTER TABLE `testimonials` ADD COLUMN `active` TINYINT(1) NOT NULL DEFAULT 1 AFTER `approved`;
ALTER TABLE `testimonials` ADD COLUMN `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER `active`;

-- 7. ANNOUNCEMENTS TABLE - Add missing columns
ALTER TABLE `announcements` ADD COLUMN `text` TEXT NOT NULL AFTER `id`;
ALTER TABLE `announcements` ADD COLUMN `link` VARCHAR(500) DEFAULT NULL AFTER `text`;
ALTER TABLE `announcements` ADD COLUMN `active` TINYINT(1) NOT NULL DEFAULT 1 AFTER `link`;
ALTER TABLE `announcements` ADD COLUMN `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER `active`;

-- 8. AFFILIATIONS TABLE - Add missing columns
ALTER TABLE `affiliations` ADD COLUMN `name` VARCHAR(255) NOT NULL DEFAULT 'Affiliate' AFTER `id`;
ALTER TABLE `affiliations` ADD COLUMN `type` ENUM('affiliation','partner') NOT NULL DEFAULT 'affiliation' AFTER `name`;
ALTER TABLE `affiliations` ADD COLUMN `logo` VARCHAR(500) DEFAULT NULL AFTER `type`;
ALTER TABLE `affiliations` ADD COLUMN `website` VARCHAR(500) DEFAULT NULL AFTER `logo`;
ALTER TABLE `affiliations` ADD COLUMN `active` TINYINT(1) NOT NULL DEFAULT 1 AFTER `website`;
ALTER TABLE `affiliations` ADD COLUMN `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER `active`;

-- 9. SETTINGS TABLE - Add missing columns
ALTER TABLE `settings` ADD COLUMN `key_name` VARCHAR(100) NOT NULL UNIQUE AFTER `id`;
ALTER TABLE `settings` ADD COLUMN `value` TEXT DEFAULT NULL AFTER `key_name`;

-- ============================================================================
-- DONE! If you got "Duplicate column name" errors, that's OK - it means
-- those columns already existed. Just ignore those errors.
-- ============================================================================
