<reponame>hedleyroos/core-access-control
"""empty message

Revision ID: e8d15433bc60
Revises: 
Create Date: 2018-03-05 15:39:06.461420

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
import access_control

# revision identifiers, used by Alembic.
revision = 'e8d15433bc60'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('domain',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('parent_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.VARCHAR(length=30), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['parent_id'], ['domain.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_domain_name'), 'domain', ['name'], unique=True)
    op.create_table('invitation',
    sa.Column('id', access_control.models.GUID(), nullable=False),
    sa.Column('first_name', sa.Text(), nullable=True),
    sa.Column('last_name', sa.Text(), nullable=True),
    sa.Column('email', sa.VARCHAR(length=100), nullable=True),
    sa.Column('expires_at', sa.DateTime(), nullable=True),
    sa.Column('invitor_id', postgresql.UUID(), nullable=True),
    sa.Column('is_system_user', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_invitation_email'), 'invitation', ['email'], unique=True)
    op.create_table('permission',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.VARCHAR(length=30), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_permission_name'), 'permission', ['name'], unique=True)
    op.create_table('resource',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('urn', sa.VARCHAR(length=100), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_resource_urn'), 'resource', ['urn'], unique=True)
    op.create_table('role',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('label', sa.VARCHAR(length=30), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('requires_2fa', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_role_label'), 'role', ['label'], unique=True)
    op.create_table('domain_role',
    sa.Column('domain_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('grant_implicitly', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['domain_id'], ['domain.id'], ),
    sa.ForeignKeyConstraint(['role_id'], ['role.id'], ),
    sa.PrimaryKeyConstraint('domain_id', 'role_id')
    )
    op.create_table('role_resource_permission',
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('resource_id', sa.Integer(), nullable=False),
    sa.Column('permission_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['permission_id'], ['permission.id'], ),
    sa.ForeignKeyConstraint(['resource_id'], ['resource.id'], ),
    sa.ForeignKeyConstraint(['role_id'], ['role.id'], ),
    sa.PrimaryKeyConstraint('role_id', 'resource_id', 'permission_id')
    )
    op.create_table('site',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.VARCHAR(length=30), nullable=True),
    sa.Column('domain_id', sa.Integer(), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('client_id', sa.VARCHAR(length=255), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['domain_id'], ['domain.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_site_client_id'), 'site', ['client_id'], unique=True)
    op.create_index(op.f('ix_site_domain_id'), 'site', ['domain_id'], unique=False)
    op.create_index(op.f('ix_site_name'), 'site', ['name'], unique=True)
    op.create_table('invitation_domain_role',
    sa.Column('invitation_id', postgresql.UUID(), nullable=False),
    sa.Column('domain_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['domain_id', 'role_id'], ['domain_role.domain_id', 'domain_role.role_id'], ),
    sa.ForeignKeyConstraint(['invitation_id'], ['invitation.id'], ),
    sa.PrimaryKeyConstraint('invitation_id', 'domain_id', 'role_id')
    )
    op.create_table('site_role',
    sa.Column('site_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('grant_implicitly', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['role.id'], ),
    sa.ForeignKeyConstraint(['site_id'], ['site.id'], ),
    sa.PrimaryKeyConstraint('site_id', 'role_id')
    )
    op.create_table('user_domain_role',
    sa.Column('user_id', postgresql.UUID(), nullable=False),
    sa.Column('domain_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['domain_id', 'role_id'], ['domain_role.domain_id', 'domain_role.role_id'], ),
    sa.PrimaryKeyConstraint('user_id', 'domain_id', 'role_id')
    )
    op.create_table('invitation_site_role',
    sa.Column('invitation_id', postgresql.UUID(), nullable=False),
    sa.Column('site_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['invitation_id'], ['invitation.id'], ),
    sa.ForeignKeyConstraint(['site_id', 'role_id'], ['site_role.site_id', 'site_role.role_id'], ),
    sa.PrimaryKeyConstraint('invitation_id', 'site_id', 'role_id')
    )
    op.create_table('user_site_role',
    sa.Column('user_id', postgresql.UUID(), nullable=False),
    sa.Column('site_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['site_id', 'role_id'], ['site_role.site_id', 'site_role.role_id'], ),
    sa.PrimaryKeyConstraint('user_id', 'site_id', 'role_id')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user_site_role')
    op.drop_table('invitation_site_role')
    op.drop_table('user_domain_role')
    op.drop_table('site_role')
    op.drop_table('invitation_domain_role')
    op.drop_index(op.f('ix_site_name'), table_name='site')
    op.drop_index(op.f('ix_site_domain_id'), table_name='site')
    op.drop_index(op.f('ix_site_client_id'), table_name='site')
    op.drop_table('site')
    op.drop_table('role_resource_permission')
    op.drop_table('domain_role')
    op.drop_index(op.f('ix_role_label'), table_name='role')
    op.drop_table('role')
    op.drop_index(op.f('ix_resource_urn'), table_name='resource')
    op.drop_table('resource')
    op.drop_index(op.f('ix_permission_name'), table_name='permission')
    op.drop_table('permission')
    op.drop_index(op.f('ix_invitation_email'), table_name='invitation')
    op.drop_table('invitation')
    op.drop_index(op.f('ix_domain_name'), table_name='domain')
    op.drop_table('domain')
    # ### end Alembic commands ###

"""empty message

Revision ID: e8d15433bc60
Revises: 
Create Date: 2018-03-05 15:39:06.461420

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
import access_control

# revision identifiers, used by Alembic.
revision = 'e8d15433bc60'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('domain',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('parent_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.VARCHAR(length=30), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['parent_id'], ['domain.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_domain_name'), 'domain', ['name'], unique=True)
    op.create_table('invitation',
    sa.Column('id', access_control.models.GUID(), nullable=False),
    sa.Column('first_name', sa.Text(), nullable=True),
    sa.Column('last_name', sa.Text(), nullable=True),
    sa.Column('email', sa.VARCHAR(length=100), nullable=True),
    sa.Column('expires_at', sa.DateTime(), nullable=True),
    sa.Column('invitor_id', postgresql.UUID(), nullable=True),
    sa.Column('is_system_user', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_invitation_email'), 'invitation', ['email'], unique=True)
    op.create_table('permission',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.VARCHAR(length=30), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_permission_name'), 'permission', ['name'], unique=True)
    op.create_table('resource',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('urn', sa.VARCHAR(length=100), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_resource_urn'), 'resource', ['urn'], unique=True)
    op.create_table('role',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('label', sa.VARCHAR(length=30), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('requires_2fa', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_role_label'), 'role', ['label'], unique=True)
    op.create_table('domain_role',
    sa.Column('domain_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('grant_implicitly', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['domain_id'], ['domain.id'], ),
    sa.ForeignKeyConstraint(['role_id'], ['role.id'], ),
    sa.PrimaryKeyConstraint('domain_id', 'role_id')
    )
    op.create_table('role_resource_permission',
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('resource_id', sa.Integer(), nullable=False),
    sa.Column('permission_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['permission_id'], ['permission.id'], ),
    sa.ForeignKeyConstraint(['resource_id'], ['resource.id'], ),
    sa.ForeignKeyConstraint(['role_id'], ['role.id'], ),
    sa.PrimaryKeyConstraint('role_id', 'resource_id', 'permission_id')
    )
    op.create_table('site',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.VARCHAR(length=30), nullable=True),
    sa.Column('domain_id', sa.Integer(), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('client_id', sa.VARCHAR(length=255), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['domain_id'], ['domain.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_site_client_id'), 'site', ['client_id'], unique=True)
    op.create_index(op.f('ix_site_domain_id'), 'site', ['domain_id'], unique=False)
    op.create_index(op.f('ix_site_name'), 'site', ['name'], unique=True)
    op.create_table('invitation_domain_role',
    sa.Column('invitation_id', postgresql.UUID(), nullable=False),
    sa.Column('domain_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['domain_id', 'role_id'], ['domain_role.domain_id', 'domain_role.role_id'], ),
    sa.ForeignKeyConstraint(['invitation_id'], ['invitation.id'], ),
    sa.PrimaryKeyConstraint('invitation_id', 'domain_id', 'role_id')
    )
    op.create_table('site_role',
    sa.Column('site_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('grant_implicitly', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['role.id'], ),
    sa.ForeignKeyConstraint(['site_id'], ['site.id'], ),
    sa.PrimaryKeyConstraint('site_id', 'role_id')
    )
    op.create_table('user_domain_role',
    sa.Column('user_id', postgresql.UUID(), nullable=False),
    sa.Column('domain_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['domain_id', 'role_id'], ['domain_role.domain_id', 'domain_role.role_id'], ),
    sa.PrimaryKeyConstraint('user_id', 'domain_id', 'role_id')
    )
    op.create_table('invitation_site_role',
    sa.Column('invitation_id', postgresql.UUID(), nullable=False),
    sa.Column('site_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['invitation_id'], ['invitation.id'], ),
    sa.ForeignKeyConstraint(['site_id', 'role_id'], ['site_role.site_id', 'site_role.role_id'], ),
    sa.PrimaryKeyConstraint('invitation_id', 'site_id', 'role_id')
    )
    op.create_table('user_site_role',
    sa.Column('user_id', postgresql.UUID(), nullable=False),
    sa.Column('site_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['site_id', 'role_id'], ['site_role.site_id', 'site_role.role_id'], ),
    sa.PrimaryKeyConstraint('user_id', 'site_id', 'role_id')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user_site_role')
    op.drop_table('invitation_site_role')
    op.drop_table('user_domain_role')
    op.drop_table('site_role')
    op.drop_table('invitation_domain_role')
    op.drop_index(op.f('ix_site_name'), table_name='site')
    op.drop_index(op.f('ix_site_domain_id'), table_name='site')
    op.drop_index(op.f('ix_site_client_id'), table_name='site')
    op.drop_table('site')
    op.drop_table('role_resource_permission')
    op.drop_table('domain_role')
    op.drop_index(op.f('ix_role_label'), table_name='role')
    op.drop_table('role')
    op.drop_index(op.f('ix_resource_urn'), table_name='resource')
    op.drop_table('resource')
    op.drop_index(op.f('ix_permission_name'), table_name='permission')
    op.drop_table('permission')
    op.drop_index(op.f('ix_invitation_email'), table_name='invitation')
    op.drop_table('invitation')
    op.drop_index(op.f('ix_domain_name'), table_name='domain')
    op.drop_table('domain')
    # ### end Alembic commands ###
empty message  Revision ID: e8d15433bc60 Revises:  Create Date: 2018-03-05 15:39:06.461420 # revision identifiers, used by Alembic. # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ### # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ###