"""initial commit

Revision ID: 5984f22b0a6
Revises: None
Create Date: 2015-08-04 13:27:22.183387

"""

# revision identifiers, used by Alembic.
revision = '5984f22b0a6'
down_revision = None

from alembic import op
import sqlalchemy as sa
from project.lib.orm.types import TypeEnum
from project.models import PageBlock, User


def upgrade():
    # commands auto generated by Alembic - please adjust!
    op.create_table(
        'category',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=50), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('name'),
    )
    op.create_table(
        'city',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=20), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('name'),
    )
    op.create_table(
        'pageblocks',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('block_type', TypeEnum(PageBlock.TYPE), nullable=False),
        sa.Column('title', sa.VARCHAR(length=128), nullable=True),
        sa.Column('text', sa.Text(), nullable=True),
        sa.Column('short_description', sa.VARCHAR(length=256), nullable=True),
        sa.Column('image', sa.Text(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
    )
    op.create_table(
        'pagechunks',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.Text(), nullable=True),
        sa.Column('text', sa.Text(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('name'),
    )
    op.create_table(
        'pages',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('title', sa.VARCHAR(length=128), nullable=True),
        sa.Column('url', sa.Text(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
    )
    op.create_table(
        'users',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('login', sa.String(length=30), nullable=False),
        sa.Column('password', sa.String(length=100), nullable=False),
        sa.Column('name', sa.String(length=30), nullable=True),
        sa.Column('surname', sa.String(length=30), nullable=True),
        sa.Column('email', sa.String(length=30), nullable=False),
        sa.Column('role', TypeEnum(User.ROLE), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('email'),
        sa.UniqueConstraint('login'),
    )
    op.create_table(
        'block_page_association',
        sa.Column('page_id', sa.Integer(), nullable=False),
        sa.Column('block_id', sa.Integer(), nullable=False),
        sa.Column('position', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['block_id'], ['pageblocks.id'], ),
        sa.ForeignKeyConstraint(['page_id'], ['pages.id'], ),
        sa.PrimaryKeyConstraint('page_id', 'block_id'),
    )
    op.create_table(
        'tokens',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('token', sa.String(), nullable=False),
        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
        sa.PrimaryKeyConstraint('id'),
    )
    op.create_table(
        'vacancy',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('title', sa.String(length=100), nullable=False),
        sa.Column('short_description', sa.String(length=300), nullable=False),
        sa.Column('text', sa.Text(), nullable=False),
        sa.Column('category_id', sa.Integer(), nullable=True),
        sa.Column('name_in_url', sa.String(length=50), nullable=False),
        sa.Column('visits', sa.Integer(), nullable=False),
        sa.Column('salary', sa.String(length=50), nullable=True),
        sa.Column('description', sa.String(length=200), nullable=True),
        sa.Column('keywords', sa.String(length=1000), nullable=True),
        sa.Column('city_id', sa.Integer(), nullable=True),
        sa.Column('hide', sa.Boolean(), nullable=False),
        sa.ForeignKeyConstraint(['category_id'], ['category.id'], ),
        sa.ForeignKeyConstraint(['city_id'], ['city.id'], ),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('name_in_url'),
    )
    # end Alembic commands


def downgrade():
    # commands auto generated by Alembic - please adjust!
    op.drop_table('vacancy')
    op.drop_table('tokens')
    op.drop_table('block_page_association')
    op.drop_table('users')
    op.drop_table('pages')
    op.drop_table('pagechunks')
    op.drop_table('pageblocks')
    op.drop_table('city')
    op.drop_table('category')
    # end Alembic commands
