-- Migration 59_create_partner_checks_table.sql
-- Create partner_checks table if not exists

CREATE TABLE IF NOT EXISTS `partner_checks` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `customer_id` INT UNSIGNED NOT NULL,
  `check_number` VARCHAR(50) NOT NULL,
  `bank_name` VARCHAR(100) DEFAULT NULL,
  `amount` BIGINT UNSIGNED NOT NULL DEFAULT 0,
  `due_date` DATE NOT NULL,
  `status` VARCHAR(20) NOT NULL DEFAULT 'pending',
  `version` INT UNSIGNED NOT NULL DEFAULT 1,
  `status_notes` TEXT DEFAULT NULL,
  `processed_by` INT UNSIGNED DEFAULT NULL,
  `processed_at` DATETIME DEFAULT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` DATETIME DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_partner_checks_customer` (`customer_id`),
  KEY `idx_partner_checks_status_due_date` (`status`, `due_date`),
  KEY `idx_partner_checks_version` (`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- SUPERSEDED: this definition diverges from the live schema and is a no‑op on a fresh database (CREATE TABLE IF NOT EXISTS after 58_create_partner_checks_table).
-- The authoritative definition is 58_create_partner_checks_table.sql plus
-- 60_alter_partner_checks_add_return.sql. The redundant 58b migration that tried
-- to add a duplicate version column and two unused indexes was removed (BUG-30).
-- Retained for history; do not edit. See BUG‑7 in PROGRESS.md.
