CREATE TABLE `tb_document_import_snapshot_cleanup`
(
    `id`              bigint UNSIGNED NOT NULL COMMENT '主键',
    `knowledge_id`    bigint UNSIGNED NULL DEFAULT NULL COMMENT '知识库ID',
    `document_id`     bigint UNSIGNED NULL DEFAULT NULL COMMENT '文档ID',
    `snapshot_type`   varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '快照类型',
    `manifest_path`   varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '快照清单路径',
    `path_hash`       char(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL COMMENT '快照清单路径SHA-256',
    `phase`           varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '清理阶段',
    `attempt_count`   int NOT NULL DEFAULT 0 COMMENT '已尝试次数',
    `next_retry_at`   datetime NOT NULL COMMENT '下次重试时间',
    `execution_token` varchar(64) CHARACTER SET ascii COLLATE ascii_bin NULL DEFAULT NULL COMMENT '执行令牌',
    `lease_until`     datetime NULL DEFAULT NULL COMMENT '租约截止时间',
    `last_error`      varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最近错误',
    `created`         datetime NULL DEFAULT NULL COMMENT '创建时间',
    `created_by`      bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人',
    `modified`        datetime NULL DEFAULT NULL COMMENT '修改时间',
    `modified_by`     bigint UNSIGNED NULL DEFAULT NULL COMMENT '修改人',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uk_document_import_snapshot_cleanup_path`
        (`snapshot_type`, `path_hash`) USING BTREE,
    INDEX `idx_document_import_snapshot_cleanup_due`
        (`next_retry_at`, `lease_until`, `id`) USING BTREE,
    INDEX `idx_document_import_snapshot_cleanup_document`
        (`document_id`, `snapshot_type`) USING BTREE
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_0900_ai_ci
  COMMENT = '文档导入中间快照清理记录'
  ROW_FORMAT = DYNAMIC;
