-- ============================================
-- DFC FIX COLUMN MISMATCH
-- This script ensures dfc_entries table has all required columns
-- Run this if you get "Column count doesn't match value count" error
-- ============================================

-- Check and add missing columns if they don't exist
SET @dbname = DATABASE();

-- Add odc_cost_2 if missing
SET @tablename = "dfc_entries";
SET @columnname = "odc_cost_2";
SET @preparedStatement = (SELECT IF(
  (
    SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
    WHERE table_name = @tablename AND table_schema = @dbname AND column_name = @columnname
  ) > 0,
  "SELECT 1",
  CONCAT("ALTER TABLE ", @tablename, " ADD COLUMN ", @columnname, " decimal(15,2) DEFAULT 0.00 AFTER odc_cost")
));
PREPARE alterIfNotExists FROM @preparedStatement;
EXECUTE alterIfNotExists;
DEALLOCATE PREPARE alterIfNotExists;

-- Verify all required columns exist
-- This query will show all columns in dfc_entries table
SELECT COLUMN_NAME, DATA_TYPE, COLUMN_DEFAULT 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = @dbname 
  AND TABLE_NAME = 'dfc_entries'
ORDER BY ORDINAL_POSITION;
