"""Add tables for user groups and user group namespace permissions

Revision ID: 02c137632f24
Revises: d72c5339c21b
Create Date: 2022-10-05 06:57:38.384099

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '02c137632f24'
down_revision = 'd72c5339c21b'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user_group',
        sa.Column('id', sa.Integer(), nullable=False, autoincrement=True),
        sa.Column('name', sa.String(length=128), nullable=False, unique=True),
        sa.Column('site_admin', sa.Boolean(), nullable=False),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_table('user_group_namespace_permission',
        sa.Column('user_group_id', sa.Integer(), nullable=False),
        sa.Column('namespace_id', sa.Integer(), nullable=False),
        sa.Column('permission_type', sa.Enum('FULL', 'MODIFY', name='usergroupnamespacepermissiontype'), nullable=True),
        sa.ForeignKeyConstraint(['namespace_id'], ['namespace.id'], name='fk_user_group_namespace_permission_namespace_id_namespace_id', onupdate='CASCADE', ondelete='CASCADE'),
        sa.ForeignKeyConstraint(['user_group_id'], ['user_group.id'], name='fk_user_group_namespace_permission_user_group_id_user_group_id', onupdate='CASCADE', ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('user_group_id', 'namespace_id')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user_group_namespace_permission')
    op.drop_table('user_group')
    # ### end Alembic commands ###
