"""user auth models

Revision ID: 12651bdf3b23
Revises: 2d71cc6b2b18
Create Date: 2015-02-17 22:14:40.783335

"""

# revision identifiers, used by Alembic.
revision = '12651bdf3b23'
down_revision = '2d71cc6b2b18'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql as pg

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(u'job_user_id_fkey', 'job', type_='foreignkey')
    op.drop_table('user')
    op.create_table('base_user',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('admin', sa.Boolean(), nullable=True),
        sa.Column('name', sa.String(length=1024), nullable=False),
        sa.Column('email', sa.String(length=256), nullable=False),
        sa.Column('phone', sa.String(length=20), nullable=True),
        sa.Column('address', sa.String(length=2048), nullable=True),
        sa.Column('verified', sa.Boolean(), nullable=True),
        sa.Column('gcm_reg_id', sa.String(), nullable=True),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_base_user_email'), 'base_user', ['email'], unique=False)
    op.create_table('service_user',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('location', pg.ARRAY(sa.Float(), dimensions=1), nullable=True),
        sa.ForeignKeyConstraint(['user_id'], ['base_user.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_table('order',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('service', sa.String(length=256), nullable=True),
        sa.Column('location', pg.ARRAY(sa.Float(), dimensions=1), nullable=True),
        sa.Column('status', sa.Enum('created', 'processing', 'assigned', 'completed', name='order_status_types'), nullable=True),
        sa.Column('request', sa.String(length=2048), nullable=True),
        sa.Column('scheduled', sa.DateTime(timezone=True), nullable=True),
        sa.Column('created', sa.DateTime(timezone=True), nullable=True),
        sa.Column('completed', sa.DateTime(timezone=True), nullable=True),
        sa.Column('address', sa.String(length=2048), nullable=True),
        sa.Column('service_user_id', sa.Integer(), nullable=True),
        sa.Column('service_provider_id', sa.Integer(), nullable=True),
        sa.Column('job_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['job_id'], ['job.id'], ),
        sa.ForeignKeyConstraint(['service_provider_id'], ['service_provider.id'], ),
        sa.ForeignKeyConstraint(['service_user_id'], ['service_user.id'], ),
        sa.PrimaryKeyConstraint('id')
    )

    op.add_column(u'job', sa.Column('service_user_id', sa.Integer(), nullable=True))
    op.create_foreign_key(u'service_user_id_fkey', 'job', 'service_user', ['service_user_id'], ['id'])
    op.drop_column(u'job', 'user_id')
    op.add_column(u'service_provider', sa.Column('user_id', sa.Integer(), nullable=True))
    op.create_foreign_key(u'service_provider_id_fkey', 'service_provider', 'base_user', ['user_id'], ['id'])
    op.drop_column(u'service_provider', 'phone_number')
    op.drop_column(u'service_provider', 'verified')
    op.drop_column(u'service_provider', 'name')
    op.drop_column(u'service_provider', 'gcm_reg_id')
    op.drop_column(u'service_provider', 'address')
    op.drop_column(u'service_provider', 'email')
    op.add_column(u'service_provider_skill', sa.Column('id', sa.Integer(), nullable=False))
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user',
        sa.Column('id', sa.INTEGER(), nullable=False),
        sa.Column('user_type', pg.ENUM(u'admin', u'user', name='user_types'), autoincrement=False, nullable=True),
        sa.Column('name', sa.VARCHAR(length=1024), autoincrement=False, nullable=False),
        sa.Column('email', sa.VARCHAR(length=256), autoincrement=False, nullable=False),
        sa.Column('phone', sa.VARCHAR(length=20), autoincrement=False, nullable=True),
        sa.Column('location', pg.ARRAY(pg.DOUBLE_PRECISION(precision=53)), autoincrement=False, nullable=True),
        sa.Column('address', sa.VARCHAR(length=2048), autoincrement=False, nullable=True),
        sa.PrimaryKeyConstraint('id', name=u'user_pkey')
    )
    op.drop_column(u'service_provider_skill', 'id')
    op.add_column(u'service_provider', sa.Column('email', sa.VARCHAR(length=256), autoincrement=False, nullable=False))
    op.add_column(u'service_provider', sa.Column('address', sa.VARCHAR(length=2048), autoincrement=False, nullable=True))
    op.add_column(u'service_provider', sa.Column('gcm_reg_id', sa.VARCHAR(), autoincrement=False, nullable=True))
    op.add_column(u'service_provider', sa.Column('name', sa.VARCHAR(length=512), autoincrement=False, nullable=False))
    op.add_column(u'service_provider', sa.Column('verified', sa.BOOLEAN(), autoincrement=False, nullable=True))
    op.add_column(u'service_provider', sa.Column('phone_number', sa.VARCHAR(length=20), autoincrement=False, nullable=True))
    op.drop_constraint(u'service_provider_id_fkey', 'service_provider', type_='foreignkey')
    op.drop_column(u'service_provider', 'user_id')
    op.add_column(u'job', sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=True))
    op.drop_constraint(u'service_user_id_fkey', 'job', type_='foreignkey')
    op.create_foreign_key(u'job_user_id_fkey', 'job', 'user', ['user_id'], ['id'])
    op.drop_column(u'job', 'service_user_id')

    op.drop_table('order')
    op.drop_table('service_user')
    op.drop_index(op.f('ix_base_user_email'), table_name='base_user')
    op.drop_table('base_user')
    ### end Alembic commands ###
