
# revision identifiers, used by Alembic.
revision = '223041bb858b'
down_revision = '2c9f3a06de09'

# Yes, this is a terrible hack. But tools/rerank_contacts.py already contains a
# script to process contacts from messages, so it's very expedient.
import sys
sys.path.append('./tools')
from rerank_contacts import rerank_contacts

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.create_table(
        'messagecontactassociation',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('contact_id', sa.Integer(), nullable=False),
        sa.Column('message_id', sa.Integer(), nullable=False),
        sa.Column('field',
                  sa.Enum('from_addr', 'to_addr', 'cc_addr', 'bcc_addr'),
                  nullable=True),
        sa.ForeignKeyConstraint(['contact_id'], ['contact.id'], ),
        sa.ForeignKeyConstraint(['message_id'], ['message.id'], ),
        sa.PrimaryKeyConstraint('id', 'contact_id', 'message_id')
    )
    rerank_contacts()


def downgrade():
    op.drop_table('messagecontactassociation')


# revision identifiers, used by Alembic.
revision = '223041bb858b'
down_revision = '2c9f3a06de09'


from alembic import op
import sqlalchemy as sa


def upgrade():
    op.create_table(
        'messagecontactassociation',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('contact_id', sa.Integer(), nullable=False),
        sa.Column('message_id', sa.Integer(), nullable=False),
        sa.Column('field',
                  sa.Enum('from_addr', 'to_addr', 'cc_addr', 'bcc_addr'),
                  nullable=True),
        sa.ForeignKeyConstraint(['contact_id'], ['contact.id'], ),
        sa.ForeignKeyConstraint(['message_id'], ['message.id'], ),
        sa.PrimaryKeyConstraint('id', 'contact_id', 'message_id')
    )

    # Yes, this is a terrible hack. But tools/rerank_contacts.py already
    # contains a script to process contacts from messages, so it's very
    # expedient.
    import sys
    sys.path.append('./tools')
    from rerank_contacts import rerank_contacts
    rerank_contacts()


def downgrade():
    op.drop_table('messagecontactassociation')

Rearrange imports in previous migration.
Rearrange imports in previous migration.

According to mg bad things can happen if you try to do stuff outside of a
migration's upgrade() function.

  
  # revision identifiers, used by Alembic.
  revision = '223041bb858b'
  down_revision = '2c9f3a06de09'
  
- # Yes, this is a terrible hack. But tools/rerank_contacts.py already contains a
- # script to process contacts from messages, so it's very expedient.
- import sys
- sys.path.append('./tools')
- from rerank_contacts import rerank_contacts
  
  from alembic import op
  import sqlalchemy as sa
  
  
  def upgrade():
      op.create_table(
          'messagecontactassociation',
          sa.Column('id', sa.Integer(), nullable=False),
          sa.Column('contact_id', sa.Integer(), nullable=False),
          sa.Column('message_id', sa.Integer(), nullable=False),
          sa.Column('field',
                    sa.Enum('from_addr', 'to_addr', 'cc_addr', 'bcc_addr'),
                    nullable=True),
          sa.ForeignKeyConstraint(['contact_id'], ['contact.id'], ),
          sa.ForeignKeyConstraint(['message_id'], ['message.id'], ),
          sa.PrimaryKeyConstraint('id', 'contact_id', 'message_id')
      )
+ 
+     # Yes, this is a terrible hack. But tools/rerank_contacts.py already
+     # contains a script to process contacts from messages, so it's very
+     # expedient.
+     import sys
+     sys.path.append('./tools')
+     from rerank_contacts import rerank_contacts
      rerank_contacts()
  
  
  def downgrade():
      op.drop_table('messagecontactassociation')
  
Rearrange imports in previous migration.
## Code Before:

# revision identifiers, used by Alembic.
revision = '223041bb858b'
down_revision = '2c9f3a06de09'

# Yes, this is a terrible hack. But tools/rerank_contacts.py already contains a
# script to process contacts from messages, so it's very expedient.
import sys
sys.path.append('./tools')
from rerank_contacts import rerank_contacts

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.create_table(
        'messagecontactassociation',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('contact_id', sa.Integer(), nullable=False),
        sa.Column('message_id', sa.Integer(), nullable=False),
        sa.Column('field',
                  sa.Enum('from_addr', 'to_addr', 'cc_addr', 'bcc_addr'),
                  nullable=True),
        sa.ForeignKeyConstraint(['contact_id'], ['contact.id'], ),
        sa.ForeignKeyConstraint(['message_id'], ['message.id'], ),
        sa.PrimaryKeyConstraint('id', 'contact_id', 'message_id')
    )
    rerank_contacts()


def downgrade():
    op.drop_table('messagecontactassociation')

## Instruction:
Rearrange imports in previous migration.
## Code After:

# revision identifiers, used by Alembic.
revision = '223041bb858b'
down_revision = '2c9f3a06de09'


from alembic import op
import sqlalchemy as sa


def upgrade():
    op.create_table(
        'messagecontactassociation',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('contact_id', sa.Integer(), nullable=False),
        sa.Column('message_id', sa.Integer(), nullable=False),
        sa.Column('field',
                  sa.Enum('from_addr', 'to_addr', 'cc_addr', 'bcc_addr'),
                  nullable=True),
        sa.ForeignKeyConstraint(['contact_id'], ['contact.id'], ),
        sa.ForeignKeyConstraint(['message_id'], ['message.id'], ),
        sa.PrimaryKeyConstraint('id', 'contact_id', 'message_id')
    )

    # Yes, this is a terrible hack. But tools/rerank_contacts.py already
    # contains a script to process contacts from messages, so it's very
    # expedient.
    import sys
    sys.path.append('./tools')
    from rerank_contacts import rerank_contacts
    rerank_contacts()


def downgrade():
    op.drop_table('messagecontactassociation')
