ALTER TABLE notification_task
    ADD COLUMN provider_message_id VARCHAR(128) DEFAULT NULL AFTER status,
    ADD COLUMN receipt_code VARCHAR(64) DEFAULT NULL AFTER provider_message_id,
    ADD COLUMN receipt_message VARCHAR(500) DEFAULT NULL AFTER receipt_code,
    ADD COLUMN receipt_at DATETIME DEFAULT NULL AFTER sent_at;

CREATE TABLE IF NOT EXISTS notification_receipt_log (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    tenant_id BIGINT UNSIGNED NOT NULL,
    task_id BIGINT UNSIGNED NOT NULL,
    provider_message_id VARCHAR(128) NOT NULL,
    receipt_code VARCHAR(64) NOT NULL,
    receipt_message VARCHAR(500) DEFAULT NULL,
    receipt_status VARCHAR(32) NOT NULL,
    created_by BIGINT UNSIGNED NOT NULL DEFAULT 0,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    KEY idx_tenant_task_time (tenant_id, task_id, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE export_task
    ADD COLUMN download_token VARCHAR(128) DEFAULT NULL AFTER file_oss_key,
    ADD COLUMN download_token_expire_at DATETIME DEFAULT NULL AFTER download_token,
    ADD COLUMN download_count INT NOT NULL DEFAULT 0 AFTER download_token_expire_at;

INSERT INTO permission (id, permission_code, permission_name, module)
VALUES
    (1070, 'export.task.download', '下载导出结果', 'export'),
    (1071, 'dashboard.read', '查看运营看板', 'dashboard')
ON DUPLICATE KEY UPDATE permission_name = VALUES(permission_name), module = VALUES(module);

INSERT INTO role_permission (id, tenant_id, role_id, permission_id)
VALUES
    (79, 1, 101, 1070),
    (80, 1, 101, 1071)
ON DUPLICATE KEY UPDATE permission_id = VALUES(permission_id);
