-- Safe migration: Add warranty and condition fields to bids table
-- This version checks if columns exist before adding them

-- Step 1: Add warrantyAvailable column (if it doesn't exist)
ALTER TABLE `bids` 
ADD COLUMN IF NOT EXISTS `warrantyAvailable` BOOLEAN DEFAULT FALSE NULL AFTER `notes`;

-- If the above fails (MySQL doesn't support IF NOT EXISTS for ALTER TABLE),
-- use this instead - it will fail if column exists, which is fine:
-- ALTER TABLE `bids` 
-- ADD COLUMN `warrantyAvailable` BOOLEAN DEFAULT FALSE NULL AFTER `notes`;

-- Step 2: Add warrantyPeriod column
ALTER TABLE `bids` 
ADD COLUMN `warrantyPeriod` INT NULL AFTER `warrantyAvailable`;

-- Step 3: Add condition column
ALTER TABLE `bids` 
ADD COLUMN `condition` ENUM('brand_new', 'used') NULL AFTER `warrantyPeriod`;

-- Step 4: Add comments for clarity (optional)
ALTER TABLE `bids` 
MODIFY COLUMN `warrantyAvailable` BOOLEAN DEFAULT FALSE NULL COMMENT 'Whether warranty is available for this part';

ALTER TABLE `bids` 
MODIFY COLUMN `warrantyPeriod` INT NULL COMMENT 'Warranty period in months (if warrantyAvailable is true)';

ALTER TABLE `bids` 
MODIFY COLUMN `condition` ENUM('brand_new', 'used') NULL COMMENT 'Condition of the spare part';

-- Verify the columns were added:
SHOW COLUMNS FROM `bids` LIKE 'warranty%';
SHOW COLUMNS FROM `bids` LIKE 'condition%';

