ALTER TABLE `tb_document_import_batch_item`
    ADD COLUMN `storage_locator` varchar(2048) NULL DEFAULT NULL
        COMMENT '可恢复存储定位符' AFTER `file_path`,
    ADD COLUMN `cleanup_pending` tinyint(1) NOT NULL DEFAULT 0
        COMMENT '是否等待清理存储对象' AFTER `storage_locator`;

UPDATE `tb_document_import_batch_item`
SET `cleanup_pending` = 1
WHERE `stage` = 'UPLOAD'
  AND `status` IN ('UPLOADING', 'CANCELLED')
  AND `file_path` IS NOT NULL;

ALTER TABLE `tb_document_import_batch_item`
    DROP INDEX `idx_document_import_batch_item_cleanup`,
    ADD INDEX `idx_document_import_batch_item_cleanup_pending`
        (`cleanup_pending`, `modified`, `id`) USING BTREE;
