|
| 1 | +"""Macro tables |
| 2 | +
|
| 3 | +Revision ID: 194838aa0431 |
| 4 | +Revises: a14f1a9b12b0 |
| 5 | +Create Date: 2024-06-05 11:42:56.258816 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | +from sqlalchemy.dialects import postgresql |
| 11 | + |
| 12 | +# revision identifiers, used by Alembic. |
| 13 | +revision = '194838aa0431' |
| 14 | +down_revision = 'a14f1a9b12b0' |
| 15 | +branch_labels = None |
| 16 | +depends_on = None |
| 17 | + |
| 18 | + |
| 19 | +def upgrade(): |
| 20 | + # ### commands auto generated by Alembic - please adjust! ### |
| 21 | + op.create_table('macro', |
| 22 | + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), |
| 23 | + sa.Column('macro_type', sa.String(), nullable=True), |
| 24 | + sa.Column('scope', sa.String(), nullable=True), |
| 25 | + sa.Column('organization_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 26 | + sa.Column('project_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 27 | + sa.Column('created_by', postgresql.UUID(as_uuid=True), nullable=True), |
| 28 | + sa.Column('created_at', sa.DateTime(), nullable=True), |
| 29 | + sa.Column('state', sa.String(), nullable=True), |
| 30 | + sa.Column('name', sa.String(), nullable=True), |
| 31 | + sa.Column('description', sa.String(), nullable=True), |
| 32 | + sa.ForeignKeyConstraint(['created_by'], ['user.id'], ondelete='SET NULL'), |
| 33 | + sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ondelete='CASCADE'), |
| 34 | + sa.ForeignKeyConstraint(['project_id'], ['cognition.project.id'], ondelete='CASCADE'), |
| 35 | + sa.PrimaryKeyConstraint('id'), |
| 36 | + schema='cognition' |
| 37 | + ) |
| 38 | + op.create_index(op.f('ix_cognition_macro_created_by'), 'macro', ['created_by'], unique=False, schema='cognition') |
| 39 | + op.create_index(op.f('ix_cognition_macro_organization_id'), 'macro', ['organization_id'], unique=False, schema='cognition') |
| 40 | + op.create_index(op.f('ix_cognition_macro_project_id'), 'macro', ['project_id'], unique=False, schema='cognition') |
| 41 | + op.create_index(op.f('ix_cognition_macro_scope'), 'macro', ['scope'], unique=False, schema='cognition') |
| 42 | + op.create_table('macro_execution', |
| 43 | + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), |
| 44 | + sa.Column('organization_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 45 | + sa.Column('macro_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 46 | + sa.Column('created_by', postgresql.UUID(as_uuid=True), nullable=True), |
| 47 | + sa.Column('created_at', sa.DateTime(), nullable=True), |
| 48 | + sa.Column('state', sa.String(), nullable=True), |
| 49 | + sa.Column('execution_group_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 50 | + sa.Column('meta_info', sa.JSON(), nullable=True), |
| 51 | + sa.ForeignKeyConstraint(['created_by'], ['user.id'], ondelete='SET NULL'), |
| 52 | + sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ondelete='CASCADE'), |
| 53 | + sa.ForeignKeyConstraint(['macro_id'], ['cognition.macro.id'], ondelete='CASCADE'), |
| 54 | + sa.PrimaryKeyConstraint('id'), |
| 55 | + schema='cognition' |
| 56 | + ) |
| 57 | + op.create_index(op.f('ix_cognition_macro_execution_created_by'), 'macro_execution', ['created_by'], unique=False, schema='cognition') |
| 58 | + op.create_index(op.f('ix_cognition_macro_execution_execution_group_id'), 'macro_execution', ['execution_group_id'], unique=False, schema='cognition') |
| 59 | + op.create_index(op.f('ix_cognition_macro_execution_macro_id'), 'macro_execution', ['macro_id'], unique=False, schema='cognition') |
| 60 | + op.create_table('macro_node', |
| 61 | + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), |
| 62 | + sa.Column('macro_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 63 | + sa.Column('created_by', postgresql.UUID(as_uuid=True), nullable=True), |
| 64 | + sa.Column('created_at', sa.DateTime(), nullable=True), |
| 65 | + sa.Column('is_root', sa.Boolean(), nullable=True), |
| 66 | + sa.Column('config', sa.JSON(), nullable=True), |
| 67 | + sa.ForeignKeyConstraint(['created_by'], ['user.id'], ondelete='SET NULL'), |
| 68 | + sa.ForeignKeyConstraint(['macro_id'], ['cognition.macro.id'], ondelete='CASCADE'), |
| 69 | + sa.PrimaryKeyConstraint('id'), |
| 70 | + schema='cognition' |
| 71 | + ) |
| 72 | + op.create_index(op.f('ix_cognition_macro_node_created_by'), 'macro_node', ['created_by'], unique=False, schema='cognition') |
| 73 | + op.create_index(op.f('ix_cognition_macro_node_macro_id'), 'macro_node', ['macro_id'], unique=False, schema='cognition') |
| 74 | + op.create_table('macro_edge', |
| 75 | + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), |
| 76 | + sa.Column('macro_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 77 | + sa.Column('from_node_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 78 | + sa.Column('to_node_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 79 | + sa.Column('created_by', postgresql.UUID(as_uuid=True), nullable=True), |
| 80 | + sa.Column('created_at', sa.DateTime(), nullable=True), |
| 81 | + sa.Column('config', sa.JSON(), nullable=True), |
| 82 | + sa.ForeignKeyConstraint(['created_by'], ['user.id'], ondelete='SET NULL'), |
| 83 | + sa.ForeignKeyConstraint(['from_node_id'], ['cognition.macro_node.id'], ondelete='CASCADE'), |
| 84 | + sa.ForeignKeyConstraint(['macro_id'], ['cognition.macro.id'], ondelete='CASCADE'), |
| 85 | + sa.ForeignKeyConstraint(['to_node_id'], ['cognition.macro_node.id'], ondelete='CASCADE'), |
| 86 | + sa.PrimaryKeyConstraint('id'), |
| 87 | + schema='cognition' |
| 88 | + ) |
| 89 | + op.create_index(op.f('ix_cognition_macro_edge_created_by'), 'macro_edge', ['created_by'], unique=False, schema='cognition') |
| 90 | + op.create_index(op.f('ix_cognition_macro_edge_from_node_id'), 'macro_edge', ['from_node_id'], unique=False, schema='cognition') |
| 91 | + op.create_index(op.f('ix_cognition_macro_edge_macro_id'), 'macro_edge', ['macro_id'], unique=False, schema='cognition') |
| 92 | + op.create_index(op.f('ix_cognition_macro_edge_to_node_id'), 'macro_edge', ['to_node_id'], unique=False, schema='cognition') |
| 93 | + op.create_table('macro_execution_link', |
| 94 | + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), |
| 95 | + sa.Column('organization_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 96 | + sa.Column('execution_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 97 | + sa.Column('execution_node_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 98 | + sa.Column('action', sa.String(), nullable=True), |
| 99 | + sa.Column('other_id_target', sa.String(), nullable=True), |
| 100 | + sa.Column('other_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 101 | + sa.ForeignKeyConstraint(['execution_id'], ['cognition.macro_execution.id'], ondelete='CASCADE'), |
| 102 | + sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ondelete='CASCADE'), |
| 103 | + sa.ForeignKeyConstraint(['execution_node_id'], ['cognition.macro_node.id'], ondelete='CASCADE'), |
| 104 | + sa.PrimaryKeyConstraint('id'), |
| 105 | + schema='cognition' |
| 106 | + ) |
| 107 | + op.create_index(op.f('ix_cognition_macro_execution_link_execution_id'), 'macro_execution_link', ['execution_id'], unique=False, schema='cognition') |
| 108 | + op.create_index(op.f('ix_cognition_macro_execution_link_execution_node_id'), 'macro_execution_link', ['execution_node_id'], unique=False, schema='cognition') |
| 109 | + op.create_index(op.f('ix_cognition_macro_execution_link_other_id'), 'macro_execution_link', ['other_id'], unique=False, schema='cognition') |
| 110 | + op.add_column('project', sa.Column('macro_config', sa.JSON(), nullable=True), schema='cognition') |
| 111 | + # ### end Alembic commands ### |
| 112 | + |
| 113 | + |
| 114 | +def downgrade(): |
| 115 | + # ### commands auto generated by Alembic - please adjust! ### |
| 116 | + op.drop_column('project', 'macro_config', schema='cognition') |
| 117 | + op.drop_index(op.f('ix_cognition_macro_execution_link_other_id'), table_name='macro_execution_link', schema='cognition') |
| 118 | + op.drop_index(op.f('ix_cognition_macro_execution_link_execution_node_id'), table_name='macro_execution_link', schema='cognition') |
| 119 | + op.drop_index(op.f('ix_cognition_macro_execution_link_execution_id'), table_name='macro_execution_link', schema='cognition') |
| 120 | + op.drop_table('macro_execution_link', schema='cognition') |
| 121 | + op.drop_index(op.f('ix_cognition_macro_edge_to_node_id'), table_name='macro_edge', schema='cognition') |
| 122 | + op.drop_index(op.f('ix_cognition_macro_edge_macro_id'), table_name='macro_edge', schema='cognition') |
| 123 | + op.drop_index(op.f('ix_cognition_macro_edge_from_node_id'), table_name='macro_edge', schema='cognition') |
| 124 | + op.drop_index(op.f('ix_cognition_macro_edge_created_by'), table_name='macro_edge', schema='cognition') |
| 125 | + op.drop_table('macro_edge', schema='cognition') |
| 126 | + op.drop_index(op.f('ix_cognition_macro_node_macro_id'), table_name='macro_node', schema='cognition') |
| 127 | + op.drop_index(op.f('ix_cognition_macro_node_created_by'), table_name='macro_node', schema='cognition') |
| 128 | + op.drop_table('macro_node', schema='cognition') |
| 129 | + op.drop_index(op.f('ix_cognition_macro_execution_macro_id'), table_name='macro_execution', schema='cognition') |
| 130 | + op.drop_index(op.f('ix_cognition_macro_execution_execution_group_id'), table_name='macro_execution', schema='cognition') |
| 131 | + op.drop_index(op.f('ix_cognition_macro_execution_created_by'), table_name='macro_execution', schema='cognition') |
| 132 | + op.drop_table('macro_execution', schema='cognition') |
| 133 | + op.drop_index(op.f('ix_cognition_macro_scope'), table_name='macro', schema='cognition') |
| 134 | + op.drop_index(op.f('ix_cognition_macro_project_id'), table_name='macro', schema='cognition') |
| 135 | + op.drop_index(op.f('ix_cognition_macro_organization_id'), table_name='macro', schema='cognition') |
| 136 | + op.drop_index(op.f('ix_cognition_macro_created_by'), table_name='macro', schema='cognition') |
| 137 | + op.drop_table('macro', schema='cognition') |
| 138 | + # ### end Alembic commands ### |
0 commit comments