"""empty message

Revision ID: 3a967695fd40
Revises: None
Create Date: 2016-04-01 04:21:57.190171

"""

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

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('acceptable_experiments_criteria',
    sa.Column('option_id', sa.Integer(), nullable=True),
    sa.Column('experiment_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['experiment_id'], ['experiment.id'], ),
    sa.ForeignKeyConstraint(['option_id'], ['filter_criteria_option.id'], )
    )
    op.create_table('attribute',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('name', sa.String(length=64), nullable=False),
    sa.Column('input_type', sa.String(length=2), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_attribute_name'), 'attribute', ['name'], unique=True)
    op.create_table('attribute_suggestion',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('experiment_id', sa.Integer(), nullable=False),
    sa.Column('text', sa.TEXT(), nullable=False),
    sa.Column('email_sent', sa.Boolean(), nullable=True),
    sa.Column('status', sa.String(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['experiment_id'], ['experiment.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('experiment',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('allow_repeats', sa.Boolean(), nullable=True),
    sa.Column('description', sa.String(length=255), nullable=True),
    sa.Column('end_date', sa.DateTime(), nullable=True),
    sa.Column('eye_tracking_enabled', sa.Boolean(), nullable=True),
    sa.Column('image_id', sa.Integer(), nullable=True),
    sa.Column('launch_date', sa.DateTime(), nullable=True),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('recordings_collected', sa.Integer(), nullable=True),
    sa.Column('recordings_to_collect', sa.Integer(), nullable=True),
    sa.Column('private', sa.Boolean(), nullable=True),
    sa.Column('status', sa.String(length=1), nullable=False),
    sa.Column('web_tracking_enabled', sa.Boolean(), nullable=True),
    sa.Column('calibration_phase_id', sa.Integer(), nullable=True),
    sa.Column('start_phase_id', sa.Integer(), nullable=True),
    sa.Column('end_phase_id', sa.Integer(), nullable=True),
    sa.Column('calibration_length', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('organization_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['calibration_phase_id'], ['phase.id'], ),
    sa.ForeignKeyConstraint(['end_phase_id'], ['phase.id'], ),
    sa.ForeignKeyConstraint(['image_id'], ['material.id'], ),
    sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
    sa.ForeignKeyConstraint(['start_phase_id'], ['phase.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_experiment_description'), 'experiment', ['description'], unique=False)
    op.create_index(op.f('ix_experiment_name'), 'experiment', ['name'], unique=False)
    op.create_table('experiments_attributes',
    sa.Column('experiment_id', sa.Integer(), nullable=True),
    sa.Column('attribute_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['attribute_id'], ['attribute.id'], ),
    sa.ForeignKeyConstraint(['experiment_id'], ['experiment.id'], )
    )
    op.create_table('filter_criteria_option',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('attribute_id', sa.Integer(), nullable=False),
    sa.Column('value', sa.String(length=255), nullable=False),
    sa.ForeignKeyConstraint(['attribute_id'], ['attribute.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('groups_phases',
    sa.Column('phase_id', sa.Integer(), nullable=True),
    sa.Column('group_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['group_id'], ['phase_group.id'], ),
    sa.ForeignKeyConstraint(['phase_id'], ['phase.id'], )
    )
    op.create_table('invitation',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('email', sa.String(length=30), nullable=False),
    sa.Column('email_sent', sa.Boolean(), nullable=True),
    sa.Column('experiment_id', sa.Integer(), nullable=False),
    sa.Column('token', sa.String(length=255), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['experiment_id'], ['experiment.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('material',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('content_type', sa.String(length=1), nullable=False),
    sa.Column('file_name', sa.String(length=255), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('organization_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('organization',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('auto_deploy', sa.Boolean(), nullable=True),
    sa.Column('description', sa.String(length=1024), nullable=True),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('owner_id', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('phase',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('experiment_id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('previous_phase_id', sa.Integer(), nullable=True),
    sa.Column('default_condition_id', sa.Integer(), nullable=True),
    sa.Column('rank', sa.Integer(), nullable=False),
    sa.Column('organization_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['default_condition_id'], ['phase_condition.id'], ),
    sa.ForeignKeyConstraint(['experiment_id'], ['experiment.id'], ),
    sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
    sa.ForeignKeyConstraint(['previous_phase_id'], ['phase.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('phase_condition',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('attribute_id', sa.Integer(), nullable=True),
    sa.Column('match_attribute', sa.Boolean(), nullable=True),
    sa.Column('operation', sa.String(length=7), nullable=True),
    sa.Column('phase_id', sa.Integer(), nullable=True),
    sa.Column('next_phase_id', sa.Integer(), nullable=True),
    sa.Column('phase_element_id', sa.Integer(), nullable=True),
    sa.Column('value_1', sa.String(length=255), nullable=True),
    sa.Column('value_2', sa.String(length=255), nullable=True),
    sa.Column('order', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['attribute_id'], ['attribute.id'], ),
    sa.ForeignKeyConstraint(['next_phase_id'], ['phase.id'], ),
    sa.ForeignKeyConstraint(['phase_element_id'], ['phase_element.id'], ),
    sa.ForeignKeyConstraint(['phase_id'], ['phase.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('phase_element',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('text', sa.TEXT(), nullable=True),
    sa.Column('lower_limit', sa.Integer(), nullable=True),
    sa.Column('upper_limit', sa.Integer(), nullable=True),
    sa.Column('material_id', sa.Integer(), nullable=True),
    sa.Column('phase_id', sa.Integer(), nullable=False),
    sa.Column('input_type', sa.String(length=2), nullable=True),
    sa.Column('category_type', sa.String(length=1), nullable=False),
    sa.Column('position', sa.Integer(), nullable=False),
    sa.Column('organization_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['material_id'], ['material.id'], ),
    sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
    sa.ForeignKeyConstraint(['phase_id'], ['phase.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('phase_element_answer',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('value', sa.String(length=255), nullable=True),
    sa.Column('material_id', sa.Integer(), nullable=True),
    sa.Column('phase_id', sa.Integer(), nullable=True),
    sa.Column('phase_element_id', sa.Integer(), nullable=True),
    sa.Column('position', sa.Integer(), nullable=False),
    sa.Column('organization_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['material_id'], ['material.id'], ),
    sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
    sa.ForeignKeyConstraint(['phase_element_id'], ['phase_element.id'], ),
    sa.ForeignKeyConstraint(['phase_id'], ['phase.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('phase_element_answer_user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('phase_id', sa.Integer(), nullable=False),
    sa.Column('phase_element_id', sa.Integer(), nullable=False),
    sa.Column('phase_element_answer_id', sa.Integer(), nullable=True),
    sa.Column('value', sa.TEXT(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['phase_element_answer_id'], ['phase_element_answer.id'], ),
    sa.ForeignKeyConstraint(['phase_element_id'], ['phase_element.id'], ),
    sa.ForeignKeyConstraint(['phase_id'], ['phase.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('phase_group',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('organization_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('possible_filter_criteria_options',
    sa.Column('option_id', sa.Integer(), nullable=True),
    sa.Column('attribute_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['attribute_id'], ['attribute.id'], ),
    sa.ForeignKeyConstraint(['option_id'], ['filter_criteria_option.id'], )
    )
    op.create_table('request_organization',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('requester_id', sa.Integer(), nullable=False),
    sa.Column('responder_id', sa.Integer(), nullable=True),
    sa.Column('response', sa.String(length=1), nullable=False),
    sa.Column('organization_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
    sa.ForeignKeyConstraint(['requester_id'], ['user.id'], ),
    sa.ForeignKeyConstraint(['responder_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('role',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('name', sa.String(length=80), nullable=False),
    sa.Column('description', sa.String(length=255), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('roles_users',
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('role_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['role.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], )
    )
    op.create_table('user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('access_token', sa.String(length=255), nullable=True),
    sa.Column('refresh_token', sa.String(length=255), nullable=True),
    sa.Column('builder', sa.Boolean(), nullable=False),
    sa.Column('email', sa.String(length=30), nullable=False),
    sa.Column('emotiv_dbapi_id', sa.Integer(), nullable=True),
    sa.Column('emotiv_eoidc_id', sa.Integer(), nullable=True),
    sa.Column('emotiv_eoidc_username', sa.String(length=255), nullable=True),
    sa.Column('first_name', sa.String(length=30), nullable=False),
    sa.Column('last_name', sa.String(length=30), nullable=False),
    sa.Column('organization_id', sa.Integer(), nullable=True),
    sa.Column('token_expires', sa.DateTime(), nullable=True),
    sa.Column('username', sa.String(length=30), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=True),
    sa.Column('confirmed_at', sa.DateTime(), nullable=True),
    sa.Column('current_login_at', sa.DateTime(), nullable=True),
    sa.Column('current_login_ip', sa.String(length=45), nullable=True),
    sa.Column('first_ip', sa.String(length=45), nullable=True),
    sa.Column('last_login_at', sa.DateTime(), nullable=True),
    sa.Column('last_login_ip', sa.String(length=45), nullable=True),
    sa.Column('login_count', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
    op.create_index(op.f('ix_user_username'), 'user', ['username'], unique=True)
    op.create_table('user_attribute',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('changed_at', sa.DateTime(), nullable=True),
    sa.Column('attribute_id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('value', sa.String(length=255), nullable=True),
    sa.ForeignKeyConstraint(['attribute_id'], ['attribute.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user_attribute')
    op.drop_index(op.f('ix_user_username'), table_name='user')
    op.drop_index(op.f('ix_user_email'), table_name='user')
    op.drop_table('user')
    op.drop_table('roles_users')
    op.drop_table('role')
    op.drop_table('request_organization')
    op.drop_table('possible_filter_criteria_options')
    op.drop_table('phase_group')
    op.drop_table('phase_element_answer_user')
    op.drop_table('phase_element_answer')
    op.drop_table('phase_element')
    op.drop_table('phase_condition')
    op.drop_table('phase')
    op.drop_table('organization')
    op.drop_table('material')
    op.drop_table('invitation')
    op.drop_table('groups_phases')
    op.drop_table('filter_criteria_option')
    op.drop_table('experiments_attributes')
    op.drop_index(op.f('ix_experiment_name'), table_name='experiment')
    op.drop_index(op.f('ix_experiment_description'), table_name='experiment')
    op.drop_table('experiment')
    op.drop_table('attribute_suggestion')
    op.drop_index(op.f('ix_attribute_name'), table_name='attribute')
    op.drop_table('attribute')
    op.drop_table('acceptable_experiments_criteria')
    ### end Alembic commands ###
