SET NAMES utf8mb4;

ALTER TABLE `tb_approval_instance`
    ADD COLUMN `application_reason` VARCHAR(500) NULL COMMENT '审批说明' AFTER `summary`;

ALTER TABLE `tb_workflow`
    ADD COLUMN `revision` INT NOT NULL DEFAULT 0 COMMENT '工作流内容修订号' AFTER `content`;

CREATE TABLE `tb_workflow_share`
(
    `id`             BIGINT UNSIGNED NOT NULL COMMENT 'ID',
    `workflow_id`    BIGINT UNSIGNED NOT NULL COMMENT '工作流ID',
    `share_key_hash` VARCHAR(64) NOT NULL COMMENT '分享密钥哈希',
    `status`         VARCHAR(32) NOT NULL COMMENT '分享状态',
    `expires_at`     DATETIME NOT NULL COMMENT '过期时间',
    `tenant_id`      BIGINT UNSIGNED NOT NULL COMMENT '租户ID',
    `dept_id`        BIGINT UNSIGNED NULL DEFAULT NULL COMMENT '部门ID',
    `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 `uni_workflow_share_key_hash` (`share_key_hash`) USING BTREE,
    INDEX `idx_workflow_share_status` (`workflow_id`, `status`) USING BTREE,
    INDEX `idx_workflow_share_expires_at` (`expires_at`) USING BTREE
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_0900_ai_ci
  COMMENT = '工作流协作分享记录'
  ROW_FORMAT = Dynamic;
