CREATE TABLE IF NOT EXISTS operation_trade_finance_profiles (
 id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, operation_id BIGINT UNSIGNED NOT NULL UNIQUE,
 instrument_type VARCHAR(50) NULL, payment_terms VARCHAR(255) NULL, issuing_bank VARCHAR(190) NULL,
 advising_bank VARCHAR(190) NULL, finance_required TINYINT(1) NOT NULL DEFAULT 0,
 finance_amount DECIMAL(20,2) NULL, currency CHAR(3) NOT NULL DEFAULT 'USD',
 created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL,
 CONSTRAINT fk_v022_finance_operation FOREIGN KEY(operation_id) REFERENCES operations(id) ON DELETE CASCADE
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS operation_timeline_v022 (
 id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, operation_id BIGINT UNSIGNED NOT NULL,
 event_type VARCHAR(60) NOT NULL DEFAULT 'note', title VARCHAR(190) NOT NULL, description TEXT NULL,
 created_by BIGINT UNSIGNED NULL, created_at DATETIME NOT NULL,
 INDEX idx_v022_timeline_operation(operation_id,created_at),
 CONSTRAINT fk_v022_timeline_operation FOREIGN KEY(operation_id) REFERENCES operations(id) ON DELETE CASCADE,
 CONSTRAINT fk_v022_timeline_user FOREIGN KEY(created_by) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS operation_checklist_v022 (
 id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, operation_id BIGINT UNSIGNED NOT NULL,
 item_group VARCHAR(60) NOT NULL DEFAULT 'commercial', title VARCHAR(255) NOT NULL,
 status VARCHAR(30) NOT NULL DEFAULT 'pending', sort_order INT NOT NULL DEFAULT 0,
 completed_by BIGINT UNSIGNED NULL, completed_at DATETIME NULL, created_at DATETIME NOT NULL,
 INDEX idx_v022_checklist_operation(operation_id,status),
 CONSTRAINT fk_v022_checklist_operation FOREIGN KEY(operation_id) REFERENCES operations(id) ON DELETE CASCADE,
 CONSTRAINT fk_v022_checklist_user FOREIGN KEY(completed_by) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB;
