"""empty message

Revision ID: 3c1542929556
Revises: None
Create Date: 2017-02-22 19:24:43.260177

"""

# revision identifiers, used by Alembic.
revision = '3c1542929556'
down_revision = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('email', sa.String(length=256), nullable=True),
    sa.Column('username', sa.String(length=64), nullable=True),
    sa.Column('confirmed', sa.Boolean(), nullable=True),
    sa.Column('sudo', sa.Boolean(), server_default='0', nullable=True),
    sa.Column('name', sa.String(length=256), nullable=True),
    sa.Column('password_hash', sa.String(length=128), nullable=True),
    sa.Column('member_since', sa.DateTime(), nullable=True),
    sa.Column('last_seen', sa.DateTime(), nullable=True),
    sa.Column('active', sa.Boolean(), server_default='1', nullable=True),
    sa.Column('enable_notification_emails', sa.Boolean(), server_default='1', nullable=False),
    sa.Column('enable_timeclock_notification_sms', sa.Boolean(), server_default='1', nullable=False),
    sa.Column('phone_country_code', sa.String(length=3), nullable=True),
    sa.Column('phone_national_number', sa.String(length=15), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
    op.create_index(op.f('ix_users_phone_country_code'), 'users', ['phone_country_code'], unique=False)
    op.create_index(op.f('ix_users_phone_national_number'), 'users', ['phone_national_number'], unique=False)
    op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
    op.create_table('apikeys',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(length=256), nullable=True),
    sa.Column('key_hash', sa.String(length=128), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('last_used', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('organizations',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=256), nullable=True),
    sa.Column('active', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('enable_shiftplanning_export', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('enable_timeclock_default', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('enable_time_off_requests_default', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('day_week_starts', sa.String(length=256), server_default='monday', nullable=False),
    sa.Column('shifts_assigned_days_before_start', sa.Integer(), server_default='4', nullable=False),
    sa.Column('workers_can_claim_shifts_in_excess_of_max', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('early_access', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('enterprise_access', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('paid_until', sa.DateTime(), nullable=True),
    sa.Column('billing_user_id', sa.Integer(), nullable=True),
    sa.Column('stripe_customer_id', sa.String(length=256), nullable=True),
    sa.Column('plan', sa.String(length=256), server_default='per-seat-v1', nullable=False),
    sa.Column('paid_labs_subscription_id', sa.String(length=256), nullable=True),
    sa.Column('trial_days', sa.Integer(), server_default='30', nullable=False),
    sa.ForeignKeyConstraint(['billing_user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_organizations_billing_user_id'), 'organizations', ['billing_user_id'], unique=False)
    op.create_table('locations',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=256), nullable=True),
    sa.Column('organization_id', sa.Integer(), nullable=True),
    sa.Column('archived', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('timezone', sa.String(length=64), server_default='UTC', nullable=False),
    sa.ForeignKeyConstraint(['organization_id'], ['organizations.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('organization_admins',
    sa.Column('organization_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['organization_id'], ['organizations.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], )
    )
    op.create_table('location_managers',
    sa.Column('location_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], )
    )
    op.create_table('roles',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=256), nullable=True),
    sa.Column('location_id', sa.Integer(), nullable=True),
    sa.Column('archived', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('enable_timeclock', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('enable_time_off_requests', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('min_half_hours_per_workday', sa.Integer(), server_default='8', nullable=False),
    sa.Column('max_half_hours_per_workday', sa.Integer(), server_default='16', nullable=False),
    sa.Column('min_half_hours_between_shifts', sa.Integer(), server_default='24', nullable=False),
    sa.Column('max_consecutive_workdays', sa.Integer(), server_default='6', nullable=False),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('recurring_shifts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('start_day', sa.String(length=256), server_default='monday', nullable=False),
    sa.Column('start_hour', sa.Integer(), server_default='9', nullable=False),
    sa.Column('start_minute', sa.Integer(), server_default='0', nullable=False),
    sa.Column('duration_minutes', sa.Integer(), server_default='480', nullable=False),
    sa.Column('quantity', sa.Integer(), server_default='1', nullable=False),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('roles_to_users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('min_half_hours_per_workweek', sa.Integer(), server_default='40', nullable=False),
    sa.Column('max_half_hours_per_workweek', sa.Integer(), server_default='80', nullable=False),
    sa.Column('internal_id', sa.String(length=256), nullable=True),
    sa.Column('working_hours', sa.LargeBinary(), nullable=True),
    sa.Column('archived', sa.Boolean(), server_default='0', nullable=False),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_roles_to_users_internal_id'), 'roles_to_users', ['internal_id'], unique=False)
    op.create_index(op.f('ix_roles_to_users_role_id'), 'roles_to_users', ['role_id'], unique=False)
    op.create_index(op.f('ix_roles_to_users_user_id'), 'roles_to_users', ['user_id'], unique=False)
    op.create_table('schedules2',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('state', sa.String(length=256), server_default='unpublished', nullable=False),
    sa.Column('demand', sa.LargeBinary(), nullable=True),
    sa.Column('start', sa.DateTime(), nullable=True),
    sa.Column('stop', sa.DateTime(), nullable=True),
    sa.Column('min_shift_length_half_hour', sa.Integer(), nullable=True),
    sa.Column('max_shift_length_half_hour', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('last_update', sa.DateTime(), nullable=True),
    sa.Column('chomp_start', sa.DateTime(), nullable=True),
    sa.Column('chomp_end', sa.DateTime(), nullable=True),
    sa.Column('mobius_start', sa.DateTime(), nullable=True),
    sa.Column('mobius_end', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_schedules2_start'), 'schedules2', ['start'], unique=False)
    op.create_index(op.f('ix_schedules2_state'), 'schedules2', ['state'], unique=False)
    op.create_index(op.f('ix_schedules2_stop'), 'schedules2', ['stop'], unique=False)
    op.create_table('shifts2',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('start', sa.DateTime(), nullable=False),
    sa.Column('stop', sa.DateTime(), nullable=False),
    sa.Column('published', sa.Boolean(), server_default='0', nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('last_update', sa.DateTime(), nullable=True),
    sa.Column('description', sa.String(length=256), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_shifts2_start'), 'shifts2', ['start'], unique=False)
    op.create_index(op.f('ix_shifts2_stop'), 'shifts2', ['stop'], unique=False)
    op.create_table('timeclocks',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('start', sa.DateTime(), nullable=False),
    sa.Column('stop', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_timeclocks_role_id'), 'timeclocks', ['role_id'], unique=False)
    op.create_index(op.f('ix_timeclocks_start'), 'timeclocks', ['start'], unique=False)
    op.create_index(op.f('ix_timeclocks_user_id'), 'timeclocks', ['user_id'], unique=False)
    op.create_table('preferences',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('schedule_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('last_update', sa.DateTime(), nullable=True),
    sa.Column('preference', sa.LargeBinary(), nullable=True),
    sa.ForeignKeyConstraint(['schedule_id'], ['schedules2.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_preferences_schedule_id'), 'preferences', ['schedule_id'], unique=False)
    op.create_index(op.f('ix_preferences_user_id'), 'preferences', ['user_id'], unique=False)
    op.create_table('timeoffrequests',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('role_to_user_id', sa.Integer(), nullable=False),
    sa.Column('start', sa.DateTime(), nullable=False),
    sa.Column('stop', sa.DateTime(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('state', sa.String(length=256), nullable=True),
    sa.Column('minutes_paid', sa.Integer(), server_default='0', nullable=False),
    sa.ForeignKeyConstraint(['role_to_user_id'], ['roles_to_users.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_timeoffrequests_role_to_user_id'), 'timeoffrequests', ['role_to_user_id'], unique=False)
    op.create_index(op.f('ix_timeoffrequests_start'), 'timeoffrequests', ['start'], unique=False)
    op.create_index(op.f('ix_timeoffrequests_state'), 'timeoffrequests', ['state'], unique=False)
    op.create_index(op.f('ix_timeoffrequests_stop'), 'timeoffrequests', ['stop'], unique=False)
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_timeoffrequests_stop'), table_name='timeoffrequests')
    op.drop_index(op.f('ix_timeoffrequests_state'), table_name='timeoffrequests')
    op.drop_index(op.f('ix_timeoffrequests_start'), table_name='timeoffrequests')
    op.drop_index(op.f('ix_timeoffrequests_role_to_user_id'), table_name='timeoffrequests')
    op.drop_table('timeoffrequests')
    op.drop_index(op.f('ix_preferences_user_id'), table_name='preferences')
    op.drop_index(op.f('ix_preferences_schedule_id'), table_name='preferences')
    op.drop_table('preferences')
    op.drop_index(op.f('ix_timeclocks_user_id'), table_name='timeclocks')
    op.drop_index(op.f('ix_timeclocks_start'), table_name='timeclocks')
    op.drop_index(op.f('ix_timeclocks_role_id'), table_name='timeclocks')
    op.drop_table('timeclocks')
    op.drop_index(op.f('ix_shifts2_stop'), table_name='shifts2')
    op.drop_index(op.f('ix_shifts2_start'), table_name='shifts2')
    op.drop_table('shifts2')
    op.drop_index(op.f('ix_schedules2_stop'), table_name='schedules2')
    op.drop_index(op.f('ix_schedules2_state'), table_name='schedules2')
    op.drop_index(op.f('ix_schedules2_start'), table_name='schedules2')
    op.drop_table('schedules2')
    op.drop_index(op.f('ix_roles_to_users_user_id'), table_name='roles_to_users')
    op.drop_index(op.f('ix_roles_to_users_role_id'), table_name='roles_to_users')
    op.drop_index(op.f('ix_roles_to_users_internal_id'), table_name='roles_to_users')
    op.drop_table('roles_to_users')
    op.drop_table('recurring_shifts')
    op.drop_table('roles')
    op.drop_table('location_managers')
    op.drop_table('organization_admins')
    op.drop_table('locations')
    op.drop_index(op.f('ix_organizations_billing_user_id'), table_name='organizations')
    op.drop_table('organizations')
    op.drop_table('apikeys')
    op.drop_index(op.f('ix_users_username'), table_name='users')
    op.drop_index(op.f('ix_users_phone_national_number'), table_name='users')
    op.drop_index(op.f('ix_users_phone_country_code'), table_name='users')
    op.drop_index(op.f('ix_users_email'), table_name='users')
    op.drop_table('users')
    ### end Alembic commands ###
