HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/migrations/versions/cd9ac3661b0d_add_workflows_tables.py
"""add workflows tables

Revision ID: cd9ac3661b0d
Revises: 6d0b558ebaf5
Create Date: 2022-06-07 12:42:38.180724

"""

# revision identifiers, used by Alembic.
from buyercall.lib.util_sqlalchemy import AwareDateTime
from sqlalchemy.dialects import postgresql
import sqlalchemy as sa
from alembic import op
revision = 'cd9ac3661b0d'
down_revision = '6d0b558ebaf5'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('workflow_condition_action',
                    sa.Column('created_on', AwareDateTime(), nullable=False),
                    sa.Column('updated_on', AwareDateTime(), nullable=False),
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('sid', postgresql.UUID(as_uuid=True), nullable=True),
                    sa.Column('is_new_contact', sa.Boolean(), server_default='1', nullable=False),
                    sa.Column('conditions', postgresql.JSON(astext_type=sa.Text()),
                              server_default='{}', nullable=False),
                    sa.Column('actions', postgresql.JSON(astext_type=sa.Text()), server_default='{}', nullable=False),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_workflow_condition_action_sid'), 'workflow_condition_action', ['sid'], unique=True)
    op.create_table('workflow_type',
                    sa.Column('created_on', AwareDateTime(), nullable=False),
                    sa.Column('updated_on', AwareDateTime(), nullable=False),
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('sid', postgresql.UUID(as_uuid=True), nullable=True),
                    sa.Column('name', sa.String(length=64), server_default='', nullable=False),
                    sa.Column('is_active', sa.Boolean(), server_default='1', nullable=False),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_workflow_type_sid'), 'workflow_type', ['sid'], unique=True)
    op.create_table('workflow',
                    sa.Column('created_on', AwareDateTime(), nullable=False),
                    sa.Column('updated_on', AwareDateTime(), nullable=False),
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('sid', postgresql.UUID(as_uuid=True), nullable=True),
                    sa.Column('name', sa.String(length=64), server_default='', nullable=False),
                    sa.Column('description', sa.String(length=512), nullable=True),
                    sa.Column('is_active', sa.Boolean(), server_default='1', nullable=False),
                    sa.Column('status', sa.Integer(), server_default='0', nullable=False),
                    sa.Column('workflow_type', sa.Integer(), nullable=True),
                    sa.Column('workflow_detail', sa.Integer(), nullable=True),
                    sa.Column('created_by', sa.Integer(), nullable=True),
                    sa.Column('updated_by', sa.Integer(), nullable=True),
                    sa.Column('partnership_account_id', sa.Integer(), nullable=True),
                    sa.Column('partnership_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['created_by'], ['users.id'], onupdate='CASCADE', ondelete='CASCADE'),
                    sa.ForeignKeyConstraint(['partnership_account_id'], ['partnership_accounts.id'],
                                            onupdate='CASCADE', ondelete='CASCADE'),
                    sa.ForeignKeyConstraint(['partnership_id'], ['partnerships.id'],
                                            onupdate='CASCADE', ondelete='CASCADE'),
                    sa.ForeignKeyConstraint(['updated_by'], ['users.id'], onupdate='CASCADE', ondelete='CASCADE'),
                    sa.ForeignKeyConstraint(['workflow_detail'], ['workflow_condition_action.id'],
                                            onupdate='CASCADE', ondelete='CASCADE'),
                    sa.ForeignKeyConstraint(['workflow_type'], ['workflow_type.id'],
                                            onupdate='CASCADE', ondelete='CASCADE'),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_workflow_created_by'), 'workflow', ['created_by'], unique=False)
    op.create_index(op.f('ix_workflow_partnership_account_id'), 'workflow', ['partnership_account_id'], unique=False)
    op.create_index(op.f('ix_workflow_partnership_id'), 'workflow', ['partnership_id'], unique=False)
    op.create_index(op.f('ix_workflow_sid'), 'workflow', ['sid'], unique=True)
    op.create_index(op.f('ix_workflow_updated_by'), 'workflow', ['updated_by'], unique=False)
    op.create_index(op.f('ix_workflow_workflow_detail'), 'workflow', ['workflow_detail'], unique=False)
    op.create_index(op.f('ix_workflow_workflow_type'), 'workflow', ['workflow_type'], unique=False)


def downgrade():

    op.drop_index(op.f('ix_workflow_workflow_type'), table_name='workflow')
    op.drop_index(op.f('ix_workflow_workflow_detail'), table_name='workflow')
    op.drop_index(op.f('ix_workflow_updated_by'), table_name='workflow')
    op.drop_index(op.f('ix_workflow_sid'), table_name='workflow')
    op.drop_index(op.f('ix_workflow_partnership_id'), table_name='workflow')
    op.drop_index(op.f('ix_workflow_partnership_account_id'), table_name='workflow')
    op.drop_index(op.f('ix_workflow_created_by'), table_name='workflow')
    op.drop_table('workflow')
    op.drop_index(op.f('ix_workflow_type_sid'), table_name='workflow_type')
    op.drop_table('workflow_type')
    op.drop_index(op.f('ix_workflow_condition_action_sid'), table_name='workflow_condition_action')
    op.drop_table('workflow_condition_action')