-- =====================================================
-- Migration: Add project_id to martial_deduction_item
-- Version: V6
-- Description: Add missing project_id column for project association
-- Date: 2026-01-16
-- =====================================================

-- Idempotent: Only add column if not exists
SET @dbname = DATABASE();
SET @tablename = 'martial_deduction_item';
SET @columnname = 'project_id';
SET @preparedStatement = (SELECT IF(
  (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS 
   WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND COLUMN_NAME = @columnname) > 0,
  'SELECT 1',
  CONCAT('ALTER TABLE ', @tablename, ' ADD COLUMN ', @columnname, ' BIGINT NULL COMMENT "项目ID"')
));
PREPARE alterIfNotExists FROM @preparedStatement;
EXECUTE alterIfNotExists;
DEALLOCATE PREPARE alterIfNotExists;
