b289e2408ee2_add_workflow.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. """add workflow
  2. Revision ID: b289e2408ee2
  3. Revises: 16830a790f0f
  4. Create Date: 2024-02-19 12:47:24.646954
  5. """
  6. import sqlalchemy as sa
  7. from alembic import op
  8. from sqlalchemy.dialects import postgresql
  9. # revision identifiers, used by Alembic.
  10. revision = 'b289e2408ee2'
  11. down_revision = 'a8d7385a7b66'
  12. branch_labels = None
  13. depends_on = None
  14. def upgrade():
  15. # ### commands auto generated by Alembic - please adjust! ###
  16. op.create_table('workflow_app_logs',
  17. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  18. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  19. sa.Column('app_id', postgresql.UUID(), nullable=False),
  20. sa.Column('workflow_id', postgresql.UUID(), nullable=False),
  21. sa.Column('workflow_run_id', postgresql.UUID(), nullable=False),
  22. sa.Column('created_from', sa.String(length=255), nullable=False),
  23. sa.Column('created_by_role', sa.String(length=255), nullable=False),
  24. sa.Column('created_by', postgresql.UUID(), nullable=False),
  25. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  26. sa.PrimaryKeyConstraint('id', name='workflow_app_log_pkey')
  27. )
  28. with op.batch_alter_table('workflow_app_logs', schema=None) as batch_op:
  29. batch_op.create_index('workflow_app_log_app_idx', ['tenant_id', 'app_id'], unique=False)
  30. op.create_table('workflow_node_executions',
  31. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  32. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  33. sa.Column('app_id', postgresql.UUID(), nullable=False),
  34. sa.Column('workflow_id', postgresql.UUID(), nullable=False),
  35. sa.Column('triggered_from', sa.String(length=255), nullable=False),
  36. sa.Column('workflow_run_id', postgresql.UUID(), nullable=True),
  37. sa.Column('index', sa.Integer(), nullable=False),
  38. sa.Column('predecessor_node_id', sa.String(length=255), nullable=True),
  39. sa.Column('node_id', sa.String(length=255), nullable=False),
  40. sa.Column('node_type', sa.String(length=255), nullable=False),
  41. sa.Column('title', sa.String(length=255), nullable=False),
  42. sa.Column('inputs', sa.Text(), nullable=True),
  43. sa.Column('process_data', sa.Text(), nullable=True),
  44. sa.Column('outputs', sa.Text(), nullable=True),
  45. sa.Column('status', sa.String(length=255), nullable=False),
  46. sa.Column('error', sa.Text(), nullable=True),
  47. sa.Column('elapsed_time', sa.Float(), server_default=sa.text('0'), nullable=False),
  48. sa.Column('execution_metadata', sa.Text(), nullable=True),
  49. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  50. sa.Column('created_by_role', sa.String(length=255), nullable=False),
  51. sa.Column('created_by', postgresql.UUID(), nullable=False),
  52. sa.Column('finished_at', sa.DateTime(), nullable=True),
  53. sa.PrimaryKeyConstraint('id', name='workflow_node_execution_pkey')
  54. )
  55. with op.batch_alter_table('workflow_node_executions', schema=None) as batch_op:
  56. batch_op.create_index('workflow_node_execution_node_run_idx', ['tenant_id', 'app_id', 'workflow_id', 'triggered_from', 'node_id'], unique=False)
  57. batch_op.create_index('workflow_node_execution_workflow_run_idx', ['tenant_id', 'app_id', 'workflow_id', 'triggered_from', 'workflow_run_id'], unique=False)
  58. op.create_table('workflow_runs',
  59. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  60. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  61. sa.Column('app_id', postgresql.UUID(), nullable=False),
  62. sa.Column('sequence_number', sa.Integer(), nullable=False),
  63. sa.Column('workflow_id', postgresql.UUID(), nullable=False),
  64. sa.Column('type', sa.String(length=255), nullable=False),
  65. sa.Column('triggered_from', sa.String(length=255), nullable=False),
  66. sa.Column('version', sa.String(length=255), nullable=False),
  67. sa.Column('graph', sa.Text(), nullable=True),
  68. sa.Column('inputs', sa.Text(), nullable=True),
  69. sa.Column('status', sa.String(length=255), nullable=False),
  70. sa.Column('outputs', sa.Text(), nullable=True),
  71. sa.Column('error', sa.Text(), nullable=True),
  72. sa.Column('elapsed_time', sa.Float(), server_default=sa.text('0'), nullable=False),
  73. sa.Column('total_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
  74. sa.Column('total_steps', sa.Integer(), server_default=sa.text('0'), nullable=True),
  75. sa.Column('created_by_role', sa.String(length=255), nullable=False),
  76. sa.Column('created_by', postgresql.UUID(), nullable=False),
  77. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  78. sa.Column('finished_at', sa.DateTime(), nullable=True),
  79. sa.PrimaryKeyConstraint('id', name='workflow_run_pkey')
  80. )
  81. with op.batch_alter_table('workflow_runs', schema=None) as batch_op:
  82. batch_op.create_index('workflow_run_triggerd_from_idx', ['tenant_id', 'app_id', 'triggered_from'], unique=False)
  83. op.create_table('workflows',
  84. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  85. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  86. sa.Column('app_id', postgresql.UUID(), nullable=False),
  87. sa.Column('type', sa.String(length=255), nullable=False),
  88. sa.Column('version', sa.String(length=255), nullable=False),
  89. sa.Column('graph', sa.Text(), nullable=True),
  90. sa.Column('features', sa.Text(), nullable=True),
  91. sa.Column('created_by', postgresql.UUID(), nullable=False),
  92. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  93. sa.Column('updated_by', postgresql.UUID(), nullable=True),
  94. sa.Column('updated_at', sa.DateTime(), nullable=True),
  95. sa.PrimaryKeyConstraint('id', name='workflow_pkey')
  96. )
  97. with op.batch_alter_table('workflows', schema=None) as batch_op:
  98. batch_op.create_index('workflow_version_idx', ['tenant_id', 'app_id', 'version'], unique=False)
  99. with op.batch_alter_table('apps', schema=None) as batch_op:
  100. batch_op.add_column(sa.Column('workflow_id', postgresql.UUID(), nullable=True))
  101. with op.batch_alter_table('messages', schema=None) as batch_op:
  102. batch_op.add_column(sa.Column('workflow_run_id', postgresql.UUID(), nullable=True))
  103. # ### end Alembic commands ###
  104. def downgrade():
  105. # ### commands auto generated by Alembic - please adjust! ###
  106. with op.batch_alter_table('messages', schema=None) as batch_op:
  107. batch_op.drop_column('workflow_run_id')
  108. with op.batch_alter_table('apps', schema=None) as batch_op:
  109. batch_op.drop_column('workflow_id')
  110. with op.batch_alter_table('workflows', schema=None) as batch_op:
  111. batch_op.drop_index('workflow_version_idx')
  112. op.drop_table('workflows')
  113. with op.batch_alter_table('workflow_runs', schema=None) as batch_op:
  114. batch_op.drop_index('workflow_run_triggerd_from_idx')
  115. op.drop_table('workflow_runs')
  116. with op.batch_alter_table('workflow_node_executions', schema=None) as batch_op:
  117. batch_op.drop_index('workflow_node_execution_workflow_run_idx')
  118. batch_op.drop_index('workflow_node_execution_node_run_idx')
  119. op.drop_table('workflow_node_executions')
  120. with op.batch_alter_table('workflow_app_logs', schema=None) as batch_op:
  121. batch_op.drop_index('workflow_app_log_app_idx')
  122. op.drop_table('workflow_app_logs')
  123. # ### end Alembic commands ###