"""init

Revision ID: 8ad96e49dc6
Revises: None
Create Date: 2015-01-08 23:14:01.941746

"""

# revision identifiers, used by Alembic.
from alembic import op
import sqlalchemy as sa

revision = '8ad96e49dc6'
down_revision = None
branch_labels = ('default',)


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('groups',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('admin', sa.Boolean(), nullable=False),
    sa.Column('super_mod', sa.Boolean(), nullable=False),
    sa.Column('mod', sa.Boolean(), nullable=False),
    sa.Column('guest', sa.Boolean(), nullable=False),
    sa.Column('banned', sa.Boolean(), nullable=False),
    sa.Column('mod_edituser', sa.Boolean(), nullable=False),
    sa.Column('mod_banuser', sa.Boolean(), nullable=False),
    sa.Column('editpost', sa.Boolean(), nullable=False),
    sa.Column('deletepost', sa.Boolean(), nullable=False),
    sa.Column('deletetopic', sa.Boolean(), nullable=False),
    sa.Column('posttopic', sa.Boolean(), nullable=False),
    sa.Column('postreply', sa.Boolean(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('categories',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=255), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('position', sa.Integer(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('settingsgroup',
    sa.Column('key', sa.String(length=255), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('description', sa.Text(), nullable=False),
    sa.PrimaryKeyConstraint('key')
    )
    op.create_table('settings',
    sa.Column('key', sa.String(length=255), nullable=False),
    sa.Column('value', sa.PickleType(), nullable=False),
    sa.Column('settingsgroup', sa.String(length=255), nullable=False),
    sa.Column('name', sa.String(length=200), nullable=False),
    sa.Column('description', sa.Text(), nullable=False),
    sa.Column('value_type', sa.String(length=20), nullable=False),
    sa.Column('extra', sa.PickleType(), nullable=True),
    sa.ForeignKeyConstraint(['settingsgroup'], ['settingsgroup.key'], name='fk_settingsgroup', use_alter=True),
    sa.PrimaryKeyConstraint('key')
    )
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('username', sa.String(length=200), nullable=False),
    sa.Column('email', sa.String(length=200), nullable=False),
    sa.Column('password', sa.String(length=120), nullable=False),
    sa.Column('date_joined', sa.DateTime(), nullable=True),
    sa.Column('lastseen', sa.DateTime(), nullable=True),
    sa.Column('birthday', sa.DateTime(), nullable=True),
    sa.Column('gender', sa.String(length=10), nullable=True),
    sa.Column('website', sa.String(length=200), nullable=True),
    sa.Column('location', sa.String(length=100), nullable=True),
    sa.Column('signature', sa.Text(), nullable=True),
    sa.Column('avatar', sa.String(length=200), nullable=True),
    sa.Column('notes', sa.Text(), nullable=True),
    sa.Column('theme', sa.String(length=15), nullable=True),
    sa.Column('language', sa.String(length=15), nullable=True),
    sa.Column('post_count', sa.Integer(), nullable=True),
    sa.Column('primary_group_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['primary_group_id'], ['groups.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email'),
    sa.UniqueConstraint('username')
    )
    op.create_table('topictracker',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('topic_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['topic_id'], ['topics.id'], name='fk_tracker_topic_id', use_alter=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], )
    )
    op.create_table('groups_users',
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('group_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['group_id'], ['groups.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], )
    )
    op.create_table('forumsread',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('forum_id', sa.Integer(), nullable=False),
    sa.Column('last_read', sa.DateTime(), nullable=True),
    sa.Column('cleared', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['forum_id'], ['forums.id'], name='fk_fr_forum_id', use_alter=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('user_id', 'forum_id')
    )
    op.create_table('moderators',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('forum_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['forum_id'], ['forums.id'], name='fk_forum_id', use_alter=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], )
    )
    op.create_table('posts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('topic_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('username', sa.String(length=200), nullable=False),
    sa.Column('content', sa.Text(), nullable=False),
    sa.Column('date_created', sa.DateTime(), nullable=True),
    sa.Column('date_modified', sa.DateTime(), nullable=True),
    sa.Column('modified_by', sa.String(length=200), nullable=True),
    sa.ForeignKeyConstraint(['topic_id'], ['topics.id'], name='fk_post_topic_id', ondelete='CASCADE', use_alter=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('privatemessages',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('from_user_id', sa.Integer(), nullable=True),
    sa.Column('to_user_id', sa.Integer(), nullable=True),
    sa.Column('subject', sa.String(length=255), nullable=True),
    sa.Column('message', sa.Text(), nullable=True),
    sa.Column('date_created', sa.DateTime(), nullable=True),
    sa.Column('trash', sa.Boolean(), nullable=False),
    sa.Column('draft', sa.Boolean(), nullable=False),
    sa.Column('unread', sa.Boolean(), nullable=False),
    sa.ForeignKeyConstraint(['from_user_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['to_user_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('topicsread',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('topic_id', sa.Integer(), nullable=False),
    sa.Column('forum_id', sa.Integer(), nullable=False),
    sa.Column('last_read', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['forum_id'], ['forums.id'], name='fk_tr_forum_id', use_alter=True),
    sa.ForeignKeyConstraint(['topic_id'], ['topics.id'], name='fk_tr_topic_id', use_alter=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('user_id', 'topic_id', 'forum_id')
    )
    op.create_table('topics',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('forum_id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=255), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('username', sa.String(length=200), nullable=False),
    sa.Column('date_created', sa.DateTime(), nullable=True),
    sa.Column('last_updated', sa.DateTime(), nullable=True),
    sa.Column('locked', sa.Boolean(), nullable=True),
    sa.Column('important', sa.Boolean(), nullable=True),
    sa.Column('views', sa.Integer(), nullable=True),
    sa.Column('post_count', sa.Integer(), nullable=True),
    sa.Column('first_post_id', sa.Integer(), nullable=True),
    sa.Column('last_post_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['first_post_id'], ['posts.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['forum_id'], ['forums.id'], name='fk_topic_forum_id', use_alter=True),
    sa.ForeignKeyConstraint(['last_post_id'], ['posts.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('reports',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('reporter_id', sa.Integer(), nullable=False),
    sa.Column('reported', sa.DateTime(), nullable=True),
    sa.Column('post_id', sa.Integer(), nullable=False),
    sa.Column('zapped', sa.DateTime(), nullable=True),
    sa.Column('zapped_by', sa.Integer(), nullable=True),
    sa.Column('reason', sa.Text(), nullable=True),
    sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ),
    sa.ForeignKeyConstraint(['reporter_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['zapped_by'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('forums',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('category_id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=255), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('position', sa.Integer(), nullable=False),
    sa.Column('locked', sa.Boolean(), nullable=False),
    sa.Column('show_moderators', sa.Boolean(), nullable=False),
    sa.Column('external', sa.String(length=200), nullable=True),
    sa.Column('post_count', sa.Integer(), nullable=False),
    sa.Column('topic_count', sa.Integer(), nullable=False),
    sa.Column('last_post_id', sa.Integer(), nullable=True),
    sa.Column('last_post_title', sa.String(length=255), nullable=True),
    sa.Column('last_post_user_id', sa.Integer(), nullable=True),
    sa.Column('last_post_username', sa.String(length=255), nullable=True),
    sa.Column('last_post_created', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
    sa.ForeignKeyConstraint(['last_post_id'], ['posts.id'], ),
    sa.ForeignKeyConstraint(['last_post_user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('forums')
    op.drop_table('reports')
    op.drop_table('topics')
    op.drop_table('topicsread')
    op.drop_table('privatemessages')
    op.drop_table('posts')
    op.drop_table('moderators')
    op.drop_table('forumsread')
    op.drop_table('groups_users')
    op.drop_table('topictracker')
    op.drop_table('users')
    op.drop_table('settings')
    op.drop_table('settingsgroup')
    op.drop_table('categories')
    op.drop_table('groups')
    ### end Alembic commands ###
