-- Migration: Add adjustment_subtype and contract_id to vouchers
-- Date: 2026-03-22

ALTER TABLE `vouchers`
  ADD COLUMN `adjustment_subtype` ENUM('financial','contract','party') NULL DEFAULT NULL AFTER `type`,
  ADD COLUMN `contract_id` INT NULL DEFAULT NULL AFTER `adjustment_subtype`,
  ADD INDEX `idx_adjustment_subtype` (`adjustment_subtype`),
  ADD INDEX `idx_contract_id` (`contract_id`);

-- Update existing adjustment vouchers to be 'financial' subtype
UPDATE `vouchers` SET `adjustment_subtype` = 'financial' WHERE `type` = 'adjustment' AND `adjustment_subtype` IS NULL;
