"""empty message

Revision ID: 8b251ccf6710
Revises: ab6f3a57b7e2
Create Date: 2022-07-17 04:27:32.251311

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from app import *
from Models import UserModel

# revision identifiers, used by Alembic.
revision = '8b251ccf6710'
down_revision = 'ab6f3a57b7e2'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('media', sa.Column('submitter_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_foreign_key(None, 'media', 'user', ['submitter_id'], ['id'])
    submitter_id = sa.table('media', sa.column('submitter_id'))
    op.execute(submitter_id.update().values(submitter_id=UserModel.matchinit_user().id))
    op.alter_column('media', 'submitter_id', nullable=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'media', type_='foreignkey')
    op.drop_column('media', 'submitter_id')
    # ### end Alembic commands ###
