[
  {
    "type": "create_table",
    "description": "Create billingInvoices table for invoice records",
    "database": "kiosk_buykiosk",
    "check_query": "SHOW TABLES LIKE 'billingInvoices'",
    "sql": "CREATE TABLE `billingInvoices` (`id` int unsigned NOT NULL AUTO_INCREMENT, `invoiceNumber` varchar(20) NOT NULL COMMENT 'Format: BK-YYMM-typeNum', `typeNum` varchar(10) NOT NULL, `billingPeriod` varchar(7) NOT NULL COMMENT 'YYYY-MM format', `periodStart` date NOT NULL, `periodEnd` date NOT NULL, `issueDate` date NOT NULL, `totalAmount` decimal(10,2) NOT NULL DEFAULT 0.00, `status` enum('finalized','voided') NOT NULL DEFAULT 'finalized', `voidedAt` datetime DEFAULT NULL, `voidedByUserId` int unsigned DEFAULT NULL, `replacedByInvoiceId` int unsigned DEFAULT NULL COMMENT 'Points to regenerated invoice', `generatedByJobId` int unsigned DEFAULT NULL COMMENT 'TaskEngine execution ID', `createdAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `updatedAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `uq_invoice_number` (`invoiceNumber`), KEY `idx_typenum` (`typeNum`), KEY `idx_period` (`billingPeriod`), KEY `idx_typenum_period_status` (`typeNum`, `billingPeriod`, `status`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Billing invoices'"
  }
]
