create table sj_retry
(
    id              bigint unsigned auto_increment comment '主键'
        primary key,
    namespace_id    varchar(64)  default '764d604ec6fc45f68cd92514c40e9e1a' not null comment '命名空间id',
    group_name      varchar(64)                                             not null comment '组名称',
    group_id        bigint                                                  not null comment '组Id',
    scene_name      varchar(64)                                             not null comment '场景名称',
    scene_id        bigint                                                  not null comment '场景ID',
    idempotent_id   varchar(64)                                             not null comment '幂等id',
    biz_no          varchar(64)  default ''                                 not null comment '业务编号',
    executor_name   varchar(512) default ''                                 not null comment '执行器名称',
    args_str        text                                                    not null comment '执行方法参数',
    ext_attrs       text                                                    not null comment '扩展字段',
    next_trigger_at bigint                                                  not null comment '下次触发时间',
    retry_count     int          default 0                                  not null comment '重试次数',
    retry_status    tinyint      default 0                                  not null comment '重试状态 0、重试中 1、成功 2、最大重试次数',
    task_type       tinyint      default 1                                  not null comment '任务类型 1、重试数据 2、回调数据',
    bucket_index    int          default 0                                  not null comment 'bucket',
    parent_id       bigint       default 0                                  not null comment '父节点id',
    deleted         bigint       default 0                                  not null comment '逻辑删除',
    create_dt       datetime     default CURRENT_TIMESTAMP                  not null comment '创建时间',
    update_dt       datetime     default CURRENT_TIMESTAMP                  not null on update CURRENT_TIMESTAMP comment '修改时间',
    constraint uk_scene_tasktype_idempotentid_deleted
        unique (scene_id, task_type, idempotent_id, deleted)
)
    comment '重试信息表';

create index idx_biz_no
    on sj_retry (biz_no);

create index idx_create_dt
    on sj_retry (create_dt);

create index idx_idempotent_id
    on sj_retry (idempotent_id);

create index idx_parent_id
    on sj_retry (parent_id);

create index idx_retry_status_bucket_index
    on sj_retry (retry_status, bucket_index);

