-- -----------------------张斌2025-06-16 15:00:00-----------------------

--------------------pgsql创建digital_human_audio表语句---------------------------
-- 音频表
CREATE TABLE IF NOT EXISTS digital_human_audio (
    -- 基础字段（继承 SQLBaseCol 通用字段，与 SQLBaseDO 对齐）
    id BIGINT PRIMARY KEY, -- 主键ID（非自增）
    tenant_id BIGINT NOT NULL DEFAULT 0, -- 租户ID int8类型
    creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 音频核心字段
    name VARCHAR(128) NOT NULL, -- 音频名称
    description TEXT DEFAULT '', -- 音频描述
    script_text TEXT NOT NULL, -- 话术文本
    audio_url VARCHAR(512) DEFAULT '', -- 音频文件URL
    status SMALLINT NOT NULL DEFAULT 0, -- 状态：0生成中/1成功/2失败
    error_msg TEXT DEFAULT '', -- 错误信息
    duration INT DEFAULT 0, -- 音频时长（秒）
    external_id VARCHAR(64) DEFAULT '', -- 外部音频ID
    voice VARCHAR(32) DEFAULT 'serena', -- 音色：serena/vivian/uncle_fu/ryan/aiden/ono_anna/sohee/eric/dylan
    voice_type VARCHAR(16) DEFAULT 'preset', -- 音色类型：preset/custom（预设/克隆）
    custom_voice VARCHAR(64) DEFAULT '' -- 自定义音色ID（用于声音克隆）
);

-- 索引
CREATE INDEX IF NOT EXISTS idx_audio_tenant_id ON digital_human_audio(tenant_id);
CREATE INDEX IF NOT EXISTS idx_audio_status ON digital_human_audio(status);
CREATE INDEX IF NOT EXISTS idx_audio_voice_type ON digital_human_audio(voice_type);
CREATE INDEX IF NOT EXISTS idx_audio_deleted_at ON digital_human_audio(deleted_at);

-- 表和字段注释
COMMENT ON TABLE digital_human_audio IS '音频表';
COMMENT ON COLUMN digital_human_audio.id IS '主键ID（非自增）';
COMMENT ON COLUMN digital_human_audio.tenant_id IS '租户ID';
COMMENT ON COLUMN digital_human_audio.creator IS '创建人';
COMMENT ON COLUMN digital_human_audio.created_at IS '创建时间';
COMMENT ON COLUMN digital_human_audio.updater IS '更新人';
COMMENT ON COLUMN digital_human_audio.updated_at IS '更新时间';
COMMENT ON COLUMN digital_human_audio.deleted_at IS '删除时间（软删）';
COMMENT ON COLUMN digital_human_audio.name IS '音频名称';
COMMENT ON COLUMN digital_human_audio.description IS '音频描述';
COMMENT ON COLUMN digital_human_audio.script_text IS '话术文本';
COMMENT ON COLUMN digital_human_audio.audio_url IS '音频文件URL';
COMMENT ON COLUMN digital_human_audio.status IS '状态：0生成中/1成功/2失败';
COMMENT ON COLUMN digital_human_audio.error_msg IS '错误信息';
COMMENT ON COLUMN digital_human_audio.duration IS '音频时长（秒）';
COMMENT ON COLUMN digital_human_audio.external_id IS '外部音频ID';
COMMENT ON COLUMN digital_human_audio.voice IS '音色：serena/vivian/uncle_fu/ryan/aiden/ono_anna/sohee/eric/dylan';
COMMENT ON COLUMN digital_human_audio.voice_type IS '音色类型：preset/custom（预设/克隆）';
COMMENT ON COLUMN digital_human_audio.custom_voice IS '自定义音色ID';

--------------------pgsql创建digital_human_custom_voice表语句---------------------------
-- 自定义音色表
CREATE TABLE IF NOT EXISTS digital_human_custom_voice (
    -- 基础字段（继承 SQLBaseCol 通用字段）
    id BIGINT PRIMARY KEY, -- 主键ID（非自增）
    tenant_id BIGINT NOT NULL DEFAULT 0, -- 租户ID int8类型
    creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 音色核心字段
    name VARCHAR(128) NOT NULL, -- 音色名称
    description TEXT DEFAULT '', -- 音色描述
    text TEXT DEFAULT '', -- 参考文本
    reference_audio BYTEA -- 参考音频数据（二进制）
);

-- 索引
CREATE INDEX IF NOT EXISTS idx_custom_voice_tenant_id ON digital_human_custom_voice(tenant_id);
CREATE INDEX IF NOT EXISTS idx_custom_voice_name ON digital_human_custom_voice(name);
CREATE INDEX IF NOT EXISTS idx_custom_voice_deleted_at ON digital_human_custom_voice(deleted_at);

-- 表和字段注释
COMMENT ON TABLE digital_human_custom_voice IS '自定义音色表';
COMMENT ON COLUMN digital_human_custom_voice.id IS '主键ID（非自增）';
COMMENT ON COLUMN digital_human_custom_voice.tenant_id IS '租户ID';
COMMENT ON COLUMN digital_human_custom_voice.creator IS '创建人';
COMMENT ON COLUMN digital_human_custom_voice.created_at IS '创建时间';
COMMENT ON COLUMN digital_human_custom_voice.updater IS '更新人';
COMMENT ON COLUMN digital_human_custom_voice.updated_at IS '更新时间';
COMMENT ON COLUMN digital_human_custom_voice.deleted_at IS '删除时间（软删）';
COMMENT ON COLUMN digital_human_custom_voice.name IS '音色名称';
COMMENT ON COLUMN digital_human_custom_voice.description IS '音色描述';
COMMENT ON COLUMN digital_human_custom_voice.text IS '参考文本';
COMMENT ON COLUMN digital_human_custom_voice.reference_audio IS '参考音频数据（二进制）';

-- 兼容已有库：自定义音色增加状态/结果字段（对接异步模型服务）
ALTER TABLE digital_human_custom_voice ADD COLUMN IF NOT EXISTS status SMALLINT NOT NULL DEFAULT 0;
ALTER TABLE digital_human_custom_voice ADD COLUMN IF NOT EXISTS error_msg TEXT DEFAULT '';
ALTER TABLE digital_human_custom_voice ADD COLUMN IF NOT EXISTS oss_file VARCHAR(512) DEFAULT '';
COMMENT ON COLUMN digital_human_custom_voice.status IS '状态：0生成中/1成功/2失败';
COMMENT ON COLUMN digital_human_custom_voice.error_msg IS '错误信息';
COMMENT ON COLUMN digital_human_custom_voice.oss_file IS '结果文件URL（如参考音频/特征文件等）';
CREATE INDEX IF NOT EXISTS idx_custom_voice_status ON digital_human_custom_voice(status);

--------------------pgsql创建digital_human_video表语句---------------------------
-- 视频表
CREATE TABLE IF NOT EXISTS digital_human_video (
    -- 基础字段
    id BIGINT PRIMARY KEY,
    tenant_id BIGINT NOT NULL DEFAULT 0,
    creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 视频核心字段
    name VARCHAR(128) NOT NULL, -- 视频名称
    description TEXT DEFAULT '', -- 视频描述
    audio_id BIGINT, -- 关联音频ID
    script_text TEXT NOT NULL, -- 话术文本
    video_url VARCHAR(512) DEFAULT '', -- 视频文件URL
    status SMALLINT NOT NULL DEFAULT 0, -- 状态：0生成中/1成功/2失败
    error_msg TEXT DEFAULT '', -- 错误信息
    duration INT DEFAULT 0, -- 视频时长（秒）
    thumbnail_url VARCHAR(512) DEFAULT '', -- 缩略图URL
    external_id VARCHAR(64) DEFAULT '', -- 外部视频ID
    digital_human_id BIGINT DEFAULT 0, -- 数字人ID（雪花算法ID）
    digital_human_name VARCHAR(128) DEFAULT '' -- 数字人名称（冗余字段）
);

-- 索引
CREATE INDEX IF NOT EXISTS idx_video_tenant_id ON digital_human_video(tenant_id);
CREATE INDEX IF NOT EXISTS idx_video_audio_id ON digital_human_video(audio_id);
CREATE INDEX IF NOT EXISTS idx_video_status ON digital_human_video(status);
CREATE INDEX IF NOT EXISTS idx_video_deleted_at ON digital_human_video(deleted_at);

-- 表和字段注释
COMMENT ON TABLE digital_human_video IS '视频表';
COMMENT ON COLUMN digital_human_video.id IS '主键ID（非自增）';
COMMENT ON COLUMN digital_human_video.tenant_id IS '租户ID';
COMMENT ON COLUMN digital_human_video.audio_id IS '关联音频ID';
COMMENT ON COLUMN digital_human_video.name IS '视频名称';
COMMENT ON COLUMN digital_human_video.description IS '视频描述';
COMMENT ON COLUMN digital_human_video.script_text IS '话术文本';
COMMENT ON COLUMN digital_human_video.video_url IS '视频文件URL';
COMMENT ON COLUMN digital_human_video.status IS '状态：0生成中/1成功/2失败';
COMMENT ON COLUMN digital_human_video.error_msg IS '错误信息';
COMMENT ON COLUMN digital_human_video.duration IS '视频时长（秒）';
COMMENT ON COLUMN digital_human_video.thumbnail_url IS '缩略图URL';
COMMENT ON COLUMN digital_human_video.external_id IS '外部视频ID';
COMMENT ON COLUMN digital_human_video.digital_human_id IS '数字人ID';
COMMENT ON COLUMN digital_human_video.digital_human_name IS '数字人名称（冗余字段）';

--------------------pgsql创建digital_human表语句---------------------------
-- 数字人表
CREATE TABLE IF NOT EXISTS digital_human (
    -- 基础字段
    id BIGINT PRIMARY KEY,
    tenant_id BIGINT NOT NULL DEFAULT 0,
    creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 数字人核心字段
    name VARCHAR(128) NOT NULL, -- 数字人名称
    description TEXT DEFAULT '', -- 数字人描述
    avatar_url VARCHAR(512) DEFAULT '', -- 头像URL
    video_url VARCHAR(512) DEFAULT '', -- 形象视频URL
    voice VARCHAR(32) DEFAULT 'serena', -- 默认音色
    status SMALLINT NOT NULL DEFAULT 1 -- 状态：1启用/0停用
);

-- 索引
CREATE INDEX IF NOT EXISTS idx_digital_human_tenant_id ON digital_human(tenant_id);
CREATE INDEX IF NOT EXISTS idx_digital_human_name ON digital_human(name);
CREATE INDEX IF NOT EXISTS idx_digital_human_status ON digital_human(status);
CREATE INDEX IF NOT EXISTS idx_digital_human_deleted_at ON digital_human(deleted_at);

-- 表和字段注释
COMMENT ON TABLE digital_human IS '数字人表';
COMMENT ON COLUMN digital_human.id IS '主键ID（非自增）';
COMMENT ON COLUMN digital_human.tenant_id IS '租户ID';
COMMENT ON COLUMN digital_human.creator IS '创建人';
COMMENT ON COLUMN digital_human.created_at IS '创建时间';
COMMENT ON COLUMN digital_human.updater IS '更新人';
COMMENT ON COLUMN digital_human.updated_at IS '更新时间';
COMMENT ON COLUMN digital_human.deleted_at IS '删除时间（软删）';
COMMENT ON COLUMN digital_human.name IS '数字人名称';
COMMENT ON COLUMN digital_human.description IS '数字人描述';
COMMENT ON COLUMN digital_human.avatar_url IS '头像URL';
COMMENT ON COLUMN digital_human.video_url IS '形象视频URL';
COMMENT ON COLUMN digital_human.voice IS '默认音色';
COMMENT ON COLUMN digital_human.status IS '状态：1启用/0停用';

--------------------pgsql创建digital_human_async_task_ref表语句---------------------------
-- 异步任务绑定表（task_id -> 业务表+业务ID）
CREATE TABLE IF NOT EXISTS digital_human_async_task_ref (
    -- 基础字段
    id BIGINT PRIMARY KEY, -- 主键ID（非自增）
    tenant_id BIGINT NOT NULL DEFAULT 0, -- 租户ID
    creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 绑定字段
    task_id VARCHAR(64) NOT NULL, -- 异步任务ID（model-asynch）
    state SMALLINT NOT NULL DEFAULT 0, -- 任务状态（与 model-asynch 对齐：0/1/2/3/4）
    table_name VARCHAR(64) NOT NULL, -- 业务表名：digital_human_audio / digital_human_custom_voice
    biz_id BIGINT NOT NULL, -- 业务表主键ID（audio/custom_voice 的 id）
    oss_file VARCHAR(512) DEFAULT '', -- 已转移后的业务侧OSS地址（可选）
    error_msg TEXT DEFAULT '' -- 错误信息（可选）
);

-- 索引
CREATE UNIQUE INDEX IF NOT EXISTS uk_async_task_ref_tenant_task_id ON digital_human_async_task_ref(tenant_id, task_id);
CREATE INDEX IF NOT EXISTS idx_async_task_ref_tenant_state ON digital_human_async_task_ref(tenant_id, state);
CREATE INDEX IF NOT EXISTS idx_async_task_ref_table_biz ON digital_human_async_task_ref(table_name, biz_id);
CREATE INDEX IF NOT EXISTS idx_async_task_ref_deleted_at ON digital_human_async_task_ref(deleted_at);

-- 注释
COMMENT ON TABLE digital_human_async_task_ref IS '异步任务绑定表（task_id -> 业务表+业务ID）';
COMMENT ON COLUMN digital_human_async_task_ref.task_id IS '异步任务ID（model-asynch）';
COMMENT ON COLUMN digital_human_async_task_ref.state IS '任务状态（与 model-asynch 对齐：0/1/2/3/4）';
COMMENT ON COLUMN digital_human_async_task_ref.table_name IS '业务表名';
COMMENT ON COLUMN digital_human_async_task_ref.biz_id IS '业务表主键ID';
COMMENT ON COLUMN digital_human_async_task_ref.oss_file IS '已转移后的业务侧OSS地址';
COMMENT ON COLUMN digital_human_async_task_ref.error_msg IS '错误信息';



-- =============================================================
-- 低代码流程编排平台 - 数据库表结构
-- Author: AI Assistant
-- =============================================================

-- 素材/创作信息表
CREATE TABLE IF NOT EXISTS black_deacon_creation_info (
    -- 基础字段（完全对齐项目规范）
                                                          id BIGINT PRIMARY KEY, -- 主键ID（非自增）
                                                          tenant_id BIGINT NOT NULL DEFAULT 0, -- 租户ID int8
                                                          creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 业务字段
    html_file_url VARCHAR(512) DEFAULT '', -- HTML文件地址
    image_urls TEXT[] DEFAULT '{}', -- 图片地址列表
    content_type VARCHAR(255) DEFAULT '', -- 素材类型
    theme VARCHAR(255) DEFAULT '', -- 主题
    title VARCHAR(255) NOT NULL -- 标题
    );

-- 索引（高频查询）
CREATE INDEX idx_creation_tenant_id ON black_deacon_creation_info(tenant_id);
CREATE INDEX idx_creation_content_type ON black_deacon_creation_info(content_type);
CREATE INDEX idx_creation_theme ON black_deacon_creation_info(theme);
CREATE INDEX idx_creation_title ON black_deacon_creation_info(title);
CREATE INDEX idx_creation_deleted_at ON black_deacon_creation_info(deleted_at);

-- 表和字段注释
COMMENT ON TABLE black_deacon_creation_info IS '素材/创作信息表';
COMMENT ON COLUMN black_deacon_creation_info.id IS '主键ID（非自增）';
COMMENT ON COLUMN black_deacon_creation_info.tenant_id IS '租户ID';
COMMENT ON COLUMN black_deacon_creation_info.creator IS '创建人';
COMMENT ON COLUMN black_deacon_creation_info.created_at IS '创建时间';
COMMENT ON COLUMN black_deacon_creation_info.updater IS '更新人';
COMMENT ON COLUMN black_deacon_creation_info.updated_at IS '更新时间';
COMMENT ON COLUMN black_deacon_creation_info.deleted_at IS '删除时间（软删）';
COMMENT ON COLUMN black_deacon_creation_info.html_file_url IS 'HTML文件地址';
COMMENT ON COLUMN black_deacon_creation_info.image_urls IS '图片地址列表';
COMMENT ON COLUMN black_deacon_creation_info.content_type IS '素材类型';
COMMENT ON COLUMN black_deacon_creation_info.theme IS '主题';
COMMENT ON COLUMN black_deacon_creation_info.title IS '标题';

--------------------pgsql创建creation_info表语句---------------------------

--------------------pgsql创建black_deacon_file_temp表语句---------------------------
-- 临时文件表
CREATE TABLE IF NOT EXISTS black_deacon_file_temp (
    -- 基础字段（完全对齐项目规范）
                                                      id BIGINT PRIMARY KEY,
                                                      tenant_id BIGINT NOT NULL DEFAULT 0,
                                                      creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 业务字段
    business_id VARCHAR(255) NOT NULL DEFAULT '',
    file_url VARCHAR(512) NOT NULL DEFAULT ''
    );

-- 索引
CREATE INDEX idx_file_temp_tenant_id ON black_deacon_file_temp(tenant_id);
CREATE INDEX idx_file_temp_business_id ON black_deacon_file_temp(business_id);
CREATE INDEX idx_file_temp_file_url ON black_deacon_file_temp(file_url);
CREATE INDEX idx_file_temp_deleted_at ON black_deacon_file_temp(deleted_at);

-- 注释
COMMENT ON TABLE black_deacon_file_temp IS '临时文件表';
COMMENT ON COLUMN black_deacon_file_temp.id IS '主键ID';
COMMENT ON COLUMN black_deacon_file_temp.tenant_id IS '租户ID';
COMMENT ON COLUMN black_deacon_file_temp.creator IS '创建人';
COMMENT ON COLUMN black_deacon_file_temp.created_at IS '创建时间';
COMMENT ON COLUMN black_deacon_file_temp.updater IS '更新人';
COMMENT ON COLUMN black_deacon_file_temp.updated_at IS '更新时间';
COMMENT ON COLUMN black_deacon_file_temp.deleted_at IS '删除时间（软删）';
COMMENT ON COLUMN black_deacon_file_temp.business_id IS '业务ID';
COMMENT ON COLUMN black_deacon_file_temp.file_url IS '文件地址';
--------------------pgsql创建black_deacon_file_temp表语句---------------------------

--------------------pgsql创建black_deacon_skill_template表语句---------------------------
-- 技能模板表
CREATE TABLE IF NOT EXISTS black_deacon_skill_template (
    -- 基础字段（完全对齐项目规范）
                                                           id BIGINT PRIMARY KEY,
                                                           tenant_id BIGINT NOT NULL DEFAULT 0,
                                                           creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 业务字段
    name VARCHAR(128) NOT NULL DEFAULT '',
    description TEXT DEFAULT '',
    file_name VARCHAR(255) NOT NULL DEFAULT '',
    file_url VARCHAR(512) NOT NULL DEFAULT ''
    );

-- 索引
CREATE INDEX idx_skill_template_tenant_id ON black_deacon_skill_template(tenant_id);
CREATE INDEX idx_skill_template_deleted_at ON black_deacon_skill_template(deleted_at);

-- 注释
COMMENT ON TABLE black_deacon_skill_template IS '技能模板表';
COMMENT ON COLUMN black_deacon_skill_template.id IS '主键ID';
COMMENT ON COLUMN black_deacon_skill_template.tenant_id IS '租户ID';
COMMENT ON COLUMN black_deacon_skill_template.creator IS '创建人';
COMMENT ON COLUMN black_deacon_skill_template.created_at IS '创建时间';
COMMENT ON COLUMN black_deacon_skill_template.updater IS '更新人';
COMMENT ON COLUMN black_deacon_skill_template.updated_at IS '更新时间';
COMMENT ON COLUMN black_deacon_skill_template.deleted_at IS '删除时间（软删）';
COMMENT ON COLUMN black_deacon_skill_template.name IS '技能模板名称';
COMMENT ON COLUMN black_deacon_skill_template.description IS '描述';
COMMENT ON COLUMN black_deacon_skill_template.file_name IS '文件名称';
COMMENT ON COLUMN black_deacon_skill_template.file_url IS '文件地址';
--------------------pgsql创建black_deacon_skill_template表语句---------------------------

--------------------pgsql创建black_deacon_skill_user表语句---------------------------
-- 技能用户表
CREATE TABLE IF NOT EXISTS black_deacon_skill_user (
    -- 基础字段（完全对齐项目规范）
                                                       id BIGINT PRIMARY KEY,
                                                       tenant_id BIGINT NOT NULL DEFAULT 0,
                                                       creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 业务字段
    name VARCHAR(128) NOT NULL DEFAULT '',
    description TEXT DEFAULT '',
    file_name VARCHAR(255) NOT NULL DEFAULT '',
    file_url VARCHAR(512) NOT NULL DEFAULT ''
    );

-- 索引
CREATE INDEX idx_skill_user_tenant_id ON black_deacon_skill_user(tenant_id);
CREATE INDEX idx_skill_user_deleted_at ON black_deacon_skill_user(deleted_at);

-- 注释
COMMENT ON TABLE black_deacon_skill_user IS '技能用户表';
COMMENT ON COLUMN black_deacon_skill_user.id IS '主键ID';
COMMENT ON COLUMN black_deacon_skill_user.tenant_id IS '租户ID';
COMMENT ON COLUMN black_deacon_skill_user.creator IS '创建人';
COMMENT ON COLUMN black_deacon_skill_user.created_at IS '创建时间';
COMMENT ON COLUMN black_deacon_skill_user.updater IS '更新人';
COMMENT ON COLUMN black_deacon_skill_user.updated_at IS '更新时间';
COMMENT ON COLUMN black_deacon_skill_user.deleted_at IS '删除时间（软删）';
COMMENT ON COLUMN black_deacon_skill_user.name IS '技能名称';
COMMENT ON COLUMN black_deacon_skill_user.description IS '描述';
COMMENT ON COLUMN black_deacon_skill_user.file_name IS '文件名称';
COMMENT ON COLUMN black_deacon_skill_user.file_url IS '文件地址';
--------------------pgsql创建black_deacon_skill_user表语句---------------------------

--------------------pgsql创建black_deacon_flow_execution表语句---------------------------
-- 流程执行记录表
CREATE TABLE IF NOT EXISTS black_deacon_flow_execution (
    -- 基础字段（完全对齐项目规范）
                                                           id BIGINT PRIMARY KEY, -- 主键ID（非自增）
                                                           tenant_id BIGINT NOT NULL DEFAULT 0, -- 租户ID int8
                                                           creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 业务字段
    flow_user_id BIGINT NOT NULL, -- 流程ID
    flow_name VARCHAR(128) NOT NULL DEFAULT '',
    trigger_type VARCHAR(32) NOT NULL DEFAULT '', -- 触发类型
    duration_ms BIGINT NOT NULL DEFAULT 0, -- 执行时长（毫秒）
    status SMALLINT NOT NULL DEFAULT 1, -- 状态:1-运行中,2-成功,3-失败
    flow_content JSONB DEFAULT '{}', -- 流程模板内容
    node_input_params JSONB DEFAULT '[]'::JSONB,
    output_params JSONB DEFAULT '[]'::JSONB,
    error_message TEXT DEFAULT '', -- 错误信息
    trace_id VARCHAR(64) DEFAULT '' -- 跟踪ID
    session_id VARCHAR(64) DEFAULT '' -- 会话ID
    );

-- 索引（高频查询）
CREATE INDEX idx_bfe_tenant_id ON black_deacon_flow_execution(tenant_id);
CREATE INDEX idx_bfe_flow_user_id ON black_deacon_flow_execution(flow_user_id);
CREATE INDEX idx_bfe_trace_id ON black_deacon_flow_execution(trace_id);
CREATE INDEX idx_bfe_status ON black_deacon_flow_execution(status);
CREATE INDEX idx_bfe_deleted_at ON black_deacon_flow_execution(deleted_at);

-- 表和字段注释
COMMENT ON TABLE black_deacon_flow_execution IS '流程执行记录表';
COMMENT ON COLUMN black_deacon_flow_execution.id IS '主键ID（非自增）';
COMMENT ON COLUMN black_deacon_flow_execution.tenant_id IS '租户ID';
COMMENT ON COLUMN black_deacon_flow_execution.creator IS '创建人';
COMMENT ON COLUMN black_deacon_flow_execution.created_at IS '创建时间';
COMMENT ON COLUMN black_deacon_flow_execution.updater IS '更新人';
COMMENT ON COLUMN black_deacon_flow_execution.updated_at IS '更新时间';
COMMENT ON COLUMN black_deacon_flow_execution.deleted_at IS '删除时间（软删）';
COMMENT ON COLUMN black_deacon_flow_execution.flow_user_id IS '流程ID';
COMMENT ON COLUMN black_deacon_flow_execution.flow_name IS '流程名称';
COMMENT ON COLUMN black_deacon_flow_execution.trigger_type IS '触发类型';
COMMENT ON COLUMN black_deacon_flow_execution.duration_ms IS '执行时长（毫秒）';
COMMENT ON COLUMN black_deacon_flow_execution.status IS '状态:1-运行中,2-成功,3-失败';
COMMENT ON COLUMN black_deacon_flow_execution.flow_content IS '流程模板内容';
COMMENT ON COLUMN black_deacon_flow_execution.node_input_params IS '节点输入参数';
COMMENT ON COLUMN black_deacon_flow_execution.output_params IS '输出参数';
COMMENT ON COLUMN black_deacon_flow_execution.error_message IS '错误信息';
COMMENT ON COLUMN black_deacon_flow_execution.trace_id IS '跟踪ID';
COMMENT ON COLUMN black_deacon_flow_execution.session_id IS '会话ID';
--------------------pgsql创建black_deacon_flow_execution表语句---------------------------

--------------------pgsql创建black_deacon_flow_user表语句---------------------------
-- 用户流程表
CREATE TABLE IF NOT EXISTS black_deacon_flow_user (
                                                      id BIGINT PRIMARY KEY,
                                                      tenant_id BIGINT NOT NULL DEFAULT 0,
                                                      creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    flow_name VARCHAR(128) NOT NULL DEFAULT '',
    description TEXT DEFAULT '',
    flow_content JSONB DEFAULT '{}',
    node_input_params JSONB DEFAULT '[]'::JSONB,
    access_level VARCHAR(32) NOT NULL DEFAULT '1',
    source_flow_template_id BIGINT NOT NULL DEFAULT 0
    );
CREATE INDEX idx_flow_user_tenant ON black_deacon_flow_user(tenant_id);
COMMENT ON TABLE black_deacon_flow_user IS '用户流程表';
COMMENT ON COLUMN black_deacon_flow_user.flow_name IS '流程名称';
COMMENT ON COLUMN black_deacon_flow_user.description IS '流程描述';
COMMENT ON COLUMN black_deacon_flow_user.flow_content IS '流程内容';
COMMENT ON COLUMN black_deacon_flow_user.node_input_params IS '节点输入参数';
COMMENT ON COLUMN black_deacon_flow_user.access_level IS '访问权限：1私有，2团队，3公开';
COMMENT ON COLUMN black_deacon_flow_user.source_flow_template_id IS '来源流程模板ID';
--------------------pgsql创建black_deacon_flow_user表语句---------------------------

--------------------pgsql创建black_deacon_flow_template表语句---------------------------
-- 流程模板表
CREATE TABLE IF NOT EXISTS black_deacon_flow_template (
    -- 基础字段（完全对齐项目规范）
                                                          id BIGINT PRIMARY KEY,
                                                          tenant_id BIGINT NOT NULL DEFAULT 0,
                                                          creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 业务字段
    flow_template_name VARCHAR(128) NOT NULL DEFAULT '',
    description TEXT DEFAULT '',
    category_code VARCHAR(64) NOT NULL DEFAULT '',
    category_name VARCHAR(64) NOT NULL DEFAULT '',
    flow_content JSONB DEFAULT '{}',
    node_input_params JSONB DEFAULT '[]',
    status SMALLINT NOT NULL DEFAULT 1
    );

-- 索引
CREATE INDEX idx_flow_template_tenant_id ON black_deacon_flow_template(tenant_id);
CREATE INDEX idx_flow_template_category_code ON black_deacon_flow_template(category_code);
CREATE INDEX idx_flow_template_status ON black_deacon_flow_template(status);
CREATE INDEX idx_flow_template_deleted_at ON black_deacon_flow_template(deleted_at);

-- 注释
COMMENT ON TABLE black_deacon_flow_template IS '流程模板表';
COMMENT ON COLUMN black_deacon_flow_template.id IS '主键ID';
COMMENT ON COLUMN black_deacon_flow_template.tenant_id IS '租户ID';
COMMENT ON COLUMN black_deacon_flow_template.creator IS '创建人';
COMMENT ON COLUMN black_deacon_flow_template.created_at IS '创建时间';
COMMENT ON COLUMN black_deacon_flow_template.updater IS '更新人';
COMMENT ON COLUMN black_deacon_flow_template.updated_at IS '更新时间';
COMMENT ON COLUMN black_deacon_flow_template.deleted_at IS '删除时间（软删）';
COMMENT ON COLUMN black_deacon_flow_template.flow_template_name IS '流程模板名称';
COMMENT ON COLUMN black_deacon_flow_template.description IS '流程描述';
COMMENT ON COLUMN black_deacon_flow_template.category_code IS '流程分类编码';
COMMENT ON COLUMN black_deacon_flow_template.category_name IS '流程分类名称';
COMMENT ON COLUMN black_deacon_flow_template.flow_content IS '流程内容';
COMMENT ON COLUMN black_deacon_flow_template.node_input_params IS '节点输入参数';
COMMENT ON COLUMN black_deacon_flow_template.status IS '流程状态：1启用/0停用';
--------------------pgsql创建black_deacon_flow_template表语句---------------------------