"""meeting invite message support

Revision ID: 576094efbb9c
Revises: 59cb1cd31420
Create Date: 2020-11-12 16:25:21.382722

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '576094efbb9c'
down_revision = '59cb1cd31420'
branch_labels = None
depends_on = None


def upgrade(engine_name):
    globals()["upgrade_%s" % engine_name]()


def downgrade(engine_name):
    globals()["downgrade_%s" % engine_name]()





def upgrade_():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('email',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('interest_id', sa.Integer(), nullable=True),
    sa.Column('meeting_id', sa.Integer(), nullable=True),
    sa.Column('type', sa.Text(), nullable=True),
    sa.Column('from_email', sa.Text(), nullable=True),
    sa.Column('subject', sa.Text(), nullable=True),
    sa.Column('message', sa.Text(), nullable=True),
    sa.Column('options', sa.Text(), nullable=True),
    sa.Column('version_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['interest_id'], ['localinterest.id'], ),
    sa.ForeignKeyConstraint(['meeting_id'], ['meeting.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('meeting', sa.Column('organizer_id', sa.Integer(), nullable=True))
    op.create_foreign_key('meeting_ibfk_2', 'meeting', 'localuser', ['organizer_id'], ['id'])
    # ### end Alembic commands ###

    # default meeting.organizer_id to 1 (owner of the application)
    from sqlalchemy.sql import table, column
    meeting = table('meeting',
                     column('organizer_id', sa.Integer()))
    op.execute(
        meeting.update().\
            values({'organizer_id':op.inline_literal(1)})
    )

def downgrade_():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('meeting_ibfk_2', 'meeting', type_='foreignkey')
    op.drop_column('meeting', 'organizer_id')
    op.drop_table('email')
    # ### end Alembic commands ###


def upgrade_users():
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###


def downgrade_users():
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###

