"""5.1.4 Update endi_payment

Revision ID: afcf321a324d
Revises: aaaaaaaaaaaa
Create Date: 2020-03-18 16:40:19.616393

"""

# revision identifiers, used by Alembic.
revision = 'afcf321a324d'
down_revision = 'aaaaaaaaaaaa'

from alembic import op
import sqlalchemy as sa


def update_database_structure():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('endi_payment_archive_seal', sa.Column('archive_type', sa.String(length=20), nullable=True))
    # ### end Alembic commands ###

def migrate_datas():
    from endi_base.models.base import DBSESSION
    session = DBSESSION()
    from alembic.context import get_bind
    conn = get_bind()
    conn.execute('update endi_payment_archive_seal set archive_type="local"')
    from zope.sqlalchemy import mark_changed
    mark_changed(session)

def upgrade():
    update_database_structure()
    migrate_datas()


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('endi_payment_archive_seal', 'archive_type')
    # ### end Alembic commands ###
