Files
saqel/backend/migrations/20260909_payment_safety_hold.sql
T

41 lines
1.9 KiB
SQL

-- Payment safety hold: apply this migration before deploying the P0 payment changes.
-- No balance is created or reconciled by this migration. Existing records remain
-- historical evidence and must be reconciled against a real provider later.
CREATE TABLE IF NOT EXISTS `cliq_payments` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`uuid` CHAR(36) NOT NULL UNIQUE,
`student_id` BIGINT UNSIGNED NOT NULL,
`course_id` BIGINT UNSIGNED NOT NULL,
`amount_jod` DECIMAL(8,2) NOT NULL,
`cliq_alias` VARCHAR(100) NOT NULL,
`reference_code` VARCHAR(50) NOT NULL UNIQUE,
`bank_transaction_id` VARCHAR(100) DEFAULT NULL UNIQUE,
`receipt_image_path` VARCHAR(500) DEFAULT NULL,
`verification_status` ENUM('pending','verified','rejected','manual_review') NOT NULL DEFAULT 'pending',
`ai_extracted_json` JSON DEFAULT NULL,
`verified_at` TIMESTAMP NULL DEFAULT NULL,
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_cliq_student` (`student_id`),
KEY `idx_cliq_ref` (`reference_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS `payout_queue` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`uuid` CHAR(36) NOT NULL UNIQUE,
`teacher_id` BIGINT UNSIGNED NOT NULL,
`amount_jod` DECIMAL(8,2) NOT NULL,
`teacher_cliq_alias` VARCHAR(150) NOT NULL,
`status` ENUM('queued','processing','completed','failed','cancelled') NOT NULL DEFAULT 'queued',
`transaction_reference` VARCHAR(100) DEFAULT NULL,
`failure_reason` TEXT DEFAULT NULL,
`processed_at` TIMESTAMP NULL DEFAULT NULL,
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_payout_teacher` (`teacher_id`),
KEY `idx_payout_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Rollback: do not drop either table. They may contain financial evidence.