CREATE TABLE IF NOT EXISTS tb_order_package_invalidate_task (
    id            bigserial    PRIMARY KEY,
    task_no       varchar(50)  NOT NULL UNIQUE,
    status        int          NOT NULL DEFAULT 1,
    total_count   int          NOT NULL DEFAULT 0,
    success_count int          NOT NULL DEFAULT 0,
    fail_count    int          NOT NULL DEFAULT 0,
    failed_items  jsonb        NOT NULL DEFAULT '[]',
    file_name     varchar(255) NOT NULL DEFAULT '',
    storage_key   varchar(500) NOT NULL DEFAULT '',
    voucher_keys  jsonb        NOT NULL DEFAULT '[]',
    remark        text         NOT NULL DEFAULT '',
    creator_name  varchar(100) NOT NULL DEFAULT '',
    error_message text         NOT NULL DEFAULT '',
    started_at    timestamptz,
    completed_at  timestamptz,
    creator       bigint       NOT NULL DEFAULT 0,
    updater       bigint       NOT NULL DEFAULT 0,
    created_at    timestamptz  NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at    timestamptz  NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at    timestamptz
);

CREATE INDEX IF NOT EXISTS idx_order_pkg_inv_task_status ON tb_order_package_invalidate_task (status) WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS idx_order_pkg_inv_task_created_at ON tb_order_package_invalidate_task (created_at DESC) WHERE deleted_at IS NULL;
