-- 创建工作流版本表
CREATE TABLE IF NOT EXISTS workflow_versions (
    id CHAR(36) PRIMARY KEY COMMENT '版本ID',
    workflow_id CHAR(36) NOT NULL COMMENT '工作流ID',
    version INT NOT NULL COMMENT '版本号',
    name VARCHAR(100) NOT NULL COMMENT '工作流名称',
    description TEXT COMMENT '描述',
    nodes JSON NOT NULL COMMENT '节点配置',
    edges JSON NOT NULL COMMENT '边配置',
    status VARCHAR(20) DEFAULT 'draft' COMMENT '状态: draft/published/running/stopped',
    created_by CHAR(36) COMMENT '创建者ID',
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    comment TEXT COMMENT '版本备注',
    FOREIGN KEY (workflow_id) REFERENCES workflows(id) ON DELETE CASCADE,
    FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
    INDEX idx_workflow_id (workflow_id),
    INDEX idx_version (workflow_id, version)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='工作流版本表';
