"""Add message type and link reply messages to originating messages

Revision ID: da83128c5c27
Revises: 174754b75952
Create Date: 2019-01-18 10:34:47.527338

"""
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils

from apollo.messaging.models import Message


# revision identifiers, used by Alembic.
revision = 'da83128c5c27'
down_revision = '174754b75952'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('message', sa.Column('message_type', sqlalchemy_utils.types.choice.ChoiceType(Message.MESSAGE_TYPES), nullable=True))
    op.add_column('message', sa.Column('originating_message_id', sa.Integer(), nullable=True))
    op.create_foreign_key('message_originating_message_id_fkey', 'message', 'message', ['originating_message_id'], ['id'], ondelete='SET NULL')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('message_originating_message_id_fkey', 'message', type_='foreignkey')
    op.drop_column('message', 'originating_message_id')
    op.drop_column('message', 'message_type')
    # ### end Alembic commands ###
