"""Initial Ringo 1.0 migration

Revision ID: 57c6ab33ad2f
Revises: None
Create Date: 2015-02-10 10:49:34.997715

"""

# revision identifiers, used by Alembic.
revision = '57c6ab33ad2f'
down_revision = None

from alembic import op
import sqlalchemy as sa


UPGRADE = """
"""
DOWNGRADE = """"""


def iter_statements(stmts):
    for st in [x for x in stmts.split('\n') if x]:
        op.execute(st)


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('roles',
    sa.Column('uuid', sa.CHAR(length=32), nullable=False),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('label', sa.String(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('description', sa.Text(), nullable=False),
    sa.Column('admin', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('label'),
    sa.UniqueConstraint('name'),
    sa.UniqueConstraint('uuid')
    )
    op.create_table('user_settings',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('settings', sa.Text(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('versions',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('values', sa.Text(), nullable=False),
    sa.Column('author', sa.String(), nullable=False),
    sa.Column('date', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('usergroups',
    sa.Column('uuid', sa.CHAR(length=32), nullable=False),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('description', sa.String(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name'),
    sa.UniqueConstraint('uuid')
    )
    op.create_table('users',
    sa.Column('uuid', sa.CHAR(length=32), nullable=False),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('login', sa.String(), nullable=False),
    sa.Column('password', sa.String(), nullable=False),
    sa.Column('activated', sa.Boolean(), nullable=True),
    sa.Column('activation_token', sa.String(), nullable=False),
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.Column('sid', sa.Integer(), nullable=True),
    sa.Column('last_login', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['gid'], ['usergroups.id'], ),
    sa.ForeignKeyConstraint(['sid'], ['user_settings.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('login'),
    sa.UniqueConstraint('uuid')
    )
    op.create_table('nm_usergroup_roles',
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.Column('rid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['gid'], ['usergroups.id'], ),
    sa.ForeignKeyConstraint(['rid'], ['roles.id'], )
    )
    op.create_table('modules',
    sa.Column('uuid', sa.CHAR(length=32), nullable=False),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('clazzpath', sa.String(), nullable=False),
    sa.Column('label', sa.String(), nullable=False),
    sa.Column('label_plural', sa.String(), nullable=False),
    sa.Column('description', sa.Text(), nullable=False),
    sa.Column('str_repr', sa.String(), nullable=False),
    sa.Column('display', sa.String(), nullable=False),
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['gid'], ['usergroups.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('clazzpath'),
    sa.UniqueConstraint('name'),
    sa.UniqueConstraint('uuid')
    )
    op.create_table('actions',
    sa.Column('uuid', sa.CHAR(length=32), nullable=False),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('mid', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('url', sa.String(), nullable=False),
    sa.Column('icon', sa.String(), nullable=False),
    sa.Column('description', sa.Text(), nullable=False),
    sa.Column('bundle', sa.Boolean(), nullable=False),
    sa.Column('display', sa.String(), nullable=False),
    sa.Column('permission', sa.String(), nullable=False),
    sa.ForeignKeyConstraint(['mid'], ['modules.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('uuid')
    )
    op.create_table('nm_user_roles',
    sa.Column('uid', sa.Integer(), nullable=True),
    sa.Column('rid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['rid'], ['roles.id'], ),
    sa.ForeignKeyConstraint(['uid'], ['users.id'], )
    )
    op.create_table('password_reset_requests',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('uid', sa.Integer(), nullable=True),
    sa.Column('created', sa.DateTime(), nullable=True),
    sa.Column('token', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['uid'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('profiles',
    sa.Column('uuid', sa.CHAR(length=32), nullable=False),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('first_name', sa.String(), nullable=True),
    sa.Column('last_name', sa.String(), nullable=True),
    sa.Column('gender', sa.Integer(), nullable=True),
    sa.Column('birthday', sa.Date(), nullable=True),
    sa.Column('address', sa.Text(), nullable=True),
    sa.Column('phone', sa.String(), nullable=True),
    sa.Column('email', sa.String(), nullable=True),
    sa.Column('web', sa.String(), nullable=True),
    sa.Column('uid', sa.Integer(), nullable=True),
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['gid'], ['usergroups.id'], ),
    sa.ForeignKeyConstraint(['uid'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('uuid')
    )
    op.create_table('nm_user_usergroups',
    sa.Column('uid', sa.Integer(), nullable=True),
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['gid'], ['usergroups.id'], ),
    sa.ForeignKeyConstraint(['uid'], ['users.id'], )
    )
    op.create_table('forms',
    sa.Column('created', sa.DateTime(), nullable=True),
    sa.Column('updated', sa.DateTime(), nullable=True),
    sa.Column('uuid', sa.CHAR(length=32), nullable=False),
    sa.Column('review_state_id', sa.Integer(), nullable=True),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('category', sa.Integer(), nullable=True),
    sa.Column('title', sa.String(), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('definition', sa.Text(), nullable=True),
    sa.Column('mid', sa.Integer(), nullable=True),
    sa.Column('uid', sa.Integer(), nullable=True),
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['gid'], ['usergroups.id'], ),
    sa.ForeignKeyConstraint(['mid'], ['modules.id'], ),
    sa.ForeignKeyConstraint(['uid'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('uuid')
    )
    op.create_table('nm_action_roles',
    sa.Column('aid', sa.Integer(), nullable=True),
    sa.Column('rid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['aid'], ['actions.id'], ),
    sa.ForeignKeyConstraint(['rid'], ['roles.id'], )
    )
    ### end Alembic commands ###
    iter_statements(UPGRADE)


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('nm_action_roles')
    op.drop_table('forms')
    op.drop_table('nm_user_usergroups')
    op.drop_table('profiles')
    op.drop_table('password_reset_requests')
    op.drop_table('nm_user_roles')
    op.drop_table('actions')
    op.drop_table('modules')
    op.drop_table('nm_usergroup_roles')
    op.drop_table('users')
    op.drop_table('usergroups')
    op.drop_table('versions')
    op.drop_table('user_settings')
    op.drop_table('roles')
    ### end Alembic commands ###
    iter_statements(DOWNGRADE)
