"""Init Schema

Revision ID: 42421a5cf46c
Revises: None
Create Date: 2014-05-08 17:52:12.218294

"""

# revision identifiers, used by Alembic.
revision = '42421a5cf46c'
down_revision = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('phantom_users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_email', sa.String(length=120), nullable=False),
    sa.Column('user_password', sa.String(length=120), nullable=False),
    sa.Column('user_created_at', sa.DateTime(), nullable=False),
    sa.Column('user_is_admin', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_phantom_users_user_email', 'phantom_users', ['user_email'], unique=True)
    op.create_table('phantom_storages',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('storage_name', sa.String(length=64), nullable=False),
    sa.Column('storage_path', sa.String(length=512), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('phantom_tasks',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('storage', sa.Integer(), nullable=True),
    sa.Column('task_name', sa.String(length=64), nullable=False),
    sa.Column('backup_path', sa.String(length=512), nullable=False),
    sa.Column('backup_time', sa.Integer(), nullable=False),
    sa.Column('task_max_stores', sa.Integer(), nullable=False),
    sa.Column('task_filename_rule', sa.String(length=32), nullable=False),
    sa.ForeignKeyConstraint(['storage'], ['phantom_storages.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_phantom_tasks_backup_time', 'phantom_tasks', ['backup_time'], unique=False)
    op.create_table('phantom_task_results',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('task', sa.Integer(), nullable=True),
    sa.Column('filename', sa.String(length=64), nullable=False),
    sa.Column('result', sa.Boolean(), nullable=True),
    sa.Column('result_executed_at', sa.DateTime(), nullable=False),
    sa.Column('result_completed_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['task'], ['phantom_tasks.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_phantom_task_results_result', 'phantom_task_results', ['result'], unique=False)
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_phantom_task_results_result', table_name='phantom_task_results')
    op.drop_table('phantom_task_results')
    op.drop_index('ix_phantom_tasks_backup_time', table_name='phantom_tasks')
    op.drop_table('phantom_tasks')
    op.drop_table('phantom_storages')
    op.drop_index('ix_phantom_users_user_email', table_name='phantom_users')
    op.drop_table('phantom_users')
    ### end Alembic commands ###
