"""Add user-society many-to-many relationship

Revision ID: 74021af9ca81
Revises: 66b34c4ccba0
Create Date: 2020-08-19 12:57:00.098210

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '74021af9ca81'
down_revision = '66b34c4ccba0'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user_society',
    sa.Column('admin_id', sa.Integer(), nullable=False),
    sa.Column('society_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['admin_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['society_id'], ['societies.id'], ),
    sa.PrimaryKeyConstraint('admin_id', 'society_id')
    )
    op.drop_constraint('users_society_id_fkey', 'users', type_='foreignkey')
    op.drop_column('users', 'society_id')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('society_id', sa.INTEGER(), autoincrement=False, nullable=False))
    op.create_foreign_key('users_society_id_fkey', 'users', 'societies', ['society_id'], ['id'])
    op.drop_table('user_society')
    # ### end Alembic commands ###
