""" Copyright 2024-2026 ChatterMate Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ """Workflow tables added Revision ID: 7fd0447b3d45 Revises: e252efacd083 Create Date: 2025-07-09 11:12:34.104222 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision: str = '7fd0447b3d45' down_revision: Union[str, None] = 'e252efacd083' branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.create_table('workflows', sa.Column('id', sa.UUID(), nullable=False), sa.Column('name', sa.String(length=100), nullable=False), sa.Column('description', sa.Text(), nullable=True), sa.Column('status', sa.Enum('DRAFT', 'PUBLISHED', 'ARCHIVED', name='workflowstatus'), nullable=True), sa.Column('version', sa.Integer(), nullable=True), sa.Column('is_template', sa.Boolean(), nullable=True), sa.Column('default_language', sa.String(length=10), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.Column('created_by', sa.UUID(), nullable=True), sa.Column('organization_id', sa.UUID(), nullable=True), sa.Column('agent_id', sa.UUID(), nullable=True), sa.Column('canvas_data', sa.JSON(), nullable=True), sa.Column('settings', sa.JSON(), nullable=True), sa.ForeignKeyConstraint(['agent_id'], ['agents.id'], ), sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.ForeignKeyConstraint(['organization_id'], ['organizations.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_table('workflow_nodes', sa.Column('id', sa.UUID(), nullable=False), sa.Column('workflow_id', sa.UUID(), nullable=False), sa.Column('node_type', sa.Enum('MESSAGE', 'LLM', 'CONDITION', 'FORM', 'ACTION', 'HUMAN_TRANSFER', 'WAIT', 'END', name='nodetype'), nullable=False), sa.Column('name', sa.String(length=100), nullable=False), sa.Column('description', sa.Text(), nullable=True), sa.Column('position_x', sa.Float(), nullable=True), sa.Column('position_y', sa.Float(), nullable=True), sa.Column('config', sa.JSON(), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), sa.Column('message_text', sa.Text(), nullable=True), sa.Column('system_prompt', sa.Text(), nullable=True), sa.Column('temperature', sa.Float(), nullable=True), sa.Column('model_id', sa.Integer(), nullable=True), sa.Column('form_fields', sa.JSON(), nullable=True), sa.Column('condition_expression', sa.Text(), nullable=True), sa.Column('action_type', sa.String(), nullable=True), sa.Column('action_config', sa.JSON(), nullable=True), sa.Column('transfer_rules', sa.JSON(), nullable=True), sa.Column('wait_duration', sa.Integer(), nullable=True), sa.Column('wait_until_condition', sa.Text(), nullable=True), sa.ForeignKeyConstraint(['model_id'], ['ai_configs.id'], ), sa.ForeignKeyConstraint(['workflow_id'], ['workflows.id'], ondelete='CASCADE'), sa.PrimaryKeyConstraint('id') ) op.create_table('workflow_connections', sa.Column('id', sa.UUID(), nullable=False), sa.Column('workflow_id', sa.UUID(), nullable=False), sa.Column('source_node_id', sa.UUID(), nullable=False), sa.Column('target_node_id', sa.UUID(), nullable=False), sa.Column('label', sa.String(length=100), nullable=True), sa.Column('condition', sa.Text(), nullable=True), sa.Column('priority', sa.Integer(), nullable=True), sa.Column('connection_metadata', sa.JSON(), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), sa.ForeignKeyConstraint(['source_node_id'], ['workflow_nodes.id'], ondelete='CASCADE'), sa.ForeignKeyConstraint(['target_node_id'], ['workflow_nodes.id'], ondelete='CASCADE'), sa.ForeignKeyConstraint(['workflow_id'], ['workflows.id'], ondelete='CASCADE'), sa.PrimaryKeyConstraint('id') ) op.add_column('agents', sa.Column('use_workflow', sa.Boolean(), nullable=True)) op.add_column('agents', sa.Column('active_workflow_id', sa.UUID(), nullable=True)) op.create_foreign_key(None, 'agents', 'workflows', ['active_workflow_id'], ['id']) op.add_column('session_to_agents', sa.Column('workflow_id', sa.UUID(), nullable=True)) op.add_column('session_to_agents', sa.Column('current_node_id', sa.UUID(), nullable=True)) op.add_column('session_to_agents', sa.Column('workflow_state', sa.JSON(), nullable=True)) op.create_foreign_key(None, 'session_to_agents', 'workflow_nodes', ['current_node_id'], ['id'], ondelete='SET NULL') op.create_foreign_key(None, 'session_to_agents', 'workflows', ['workflow_id'], ['id'], ondelete='SET NULL') # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_constraint(None, 'session_to_agents', type_='foreignkey') op.drop_constraint(None, 'session_to_agents', type_='foreignkey') op.drop_column('session_to_agents', 'workflow_state') op.drop_column('session_to_agents', 'current_node_id') op.drop_column('session_to_agents', 'workflow_id') op.drop_constraint(None, 'agents', type_='foreignkey') op.drop_column('agents', 'active_workflow_id') op.drop_column('agents', 'use_workflow') op.drop_table('workflow_connections') op.drop_table('workflow_nodes') op.drop_table('workflows') # ### end Alembic commands ###