"""start

Revision ID: 0001
Revises: 
Create Date: 2016-04-13 19:54:05.937035

"""

# revision identifiers, used by Alembic.
revision = '0001'
down_revision = None
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
import whisker


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('master_config',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=True),
    sa.Column('modified_at', whisker.sqlalchemy.ArrowMicrosecondType(), nullable=True),
    sa.Column('server', sa.String(length=255), nullable=True),
    sa.Column('port', sa.Integer(), nullable=True),
    sa.Column('wcm_prefix', sa.String(length=255), nullable=True),
    sa.Column('rfid_effective_time_s', sa.Float(), nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_master_config'))
    )
    op.create_table('rfidreader_config',
    sa.Column('port', sa.String(length=255), nullable=True),
    sa.Column('baudrate', sa.Integer(), nullable=True),
    sa.Column('bytesize', sa.Integer(), nullable=True),
    sa.Column('parity', sa.String(length=1), nullable=True),
    sa.Column('stopbits', sa.Float(), nullable=True),
    sa.Column('xonxoff', sa.Boolean(), nullable=True),
    sa.Column('rtscts', sa.Boolean(), nullable=True),
    sa.Column('dsrdtr', sa.Boolean(), nullable=True),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('master_config_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(length=255), nullable=True),
    sa.Column('enabled', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['master_config_id'], ['master_config.id'], name=op.f('fk_rfidreader_config_master_config_id_master_config')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_rfidreader_config'))
    )
    op.create_table('balance_config',
    sa.Column('port', sa.String(length=255), nullable=True),
    sa.Column('baudrate', sa.Integer(), nullable=True),
    sa.Column('bytesize', sa.Integer(), nullable=True),
    sa.Column('parity', sa.String(length=1), nullable=True),
    sa.Column('stopbits', sa.Float(), nullable=True),
    sa.Column('xonxoff', sa.Boolean(), nullable=True),
    sa.Column('rtscts', sa.Boolean(), nullable=True),
    sa.Column('dsrdtr', sa.Boolean(), nullable=True),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('master_config_id', sa.Integer(), nullable=True),
    sa.Column('reader_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(length=255), nullable=True),
    sa.Column('enabled', sa.Boolean(), nullable=True),
    sa.Column('measurement_rate_hz', sa.Integer(), nullable=True),
    sa.Column('stability_n', sa.Integer(), nullable=True),
    sa.Column('tolerance_kg', sa.Float(), nullable=True),
    sa.Column('min_mass_kg', sa.Float(), nullable=True),
    sa.Column('unlock_mass_kg', sa.Float(), nullable=True),
    sa.Column('refload_mass_kg', sa.Float(), nullable=True),
    sa.Column('zero_value', sa.Integer(), nullable=True),
    sa.Column('refload_value', sa.Integer(), nullable=True),
    sa.Column('read_continuously', sa.Boolean(), nullable=True),
    sa.Column('amp_signal_filter_mode', sa.Integer(), nullable=True),
    sa.Column('fast_response_filter', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['master_config_id'], ['master_config.id'], name=op.f('fk_balance_config_master_config_id_master_config')),
    sa.ForeignKeyConstraint(['reader_id'], ['rfidreader_config.id'], name=op.f('fk_balance_config_reader_id_rfidreader_config')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_balance_config'))
    )
    op.create_table('rfid_event',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('reader_id', sa.Integer(), nullable=True),
    sa.Column('rfid', sa.BigInteger(), nullable=True),
    sa.Column('first_detected_at', whisker.sqlalchemy.ArrowMicrosecondType(), nullable=True),
    sa.Column('last_detected_at', whisker.sqlalchemy.ArrowMicrosecondType(), nullable=True),
    sa.Column('n_events', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['reader_id'], ['rfidreader_config.id'], name=op.f('fk_rfid_event_reader_id_rfidreader_config')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_rfid_event'))
    )
    op.create_table('mass_event',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('rfid', sa.BigInteger(), nullable=True),
    sa.Column('reader_id', sa.Integer(), nullable=True),
    sa.Column('balance_id', sa.Integer(), nullable=True),
    sa.Column('at', whisker.sqlalchemy.ArrowMicrosecondType(), nullable=True),
    sa.Column('mass_kg', sa.Float(), nullable=True),
    sa.ForeignKeyConstraint(['balance_id'], ['balance_config.id'], name=op.f('fk_mass_event_balance_id_balance_config')),
    sa.ForeignKeyConstraint(['reader_id'], ['rfidreader_config.id'], name=op.f('fk_mass_event_reader_id_rfidreader_config')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_mass_event'))
    )
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('mass_event')
    op.drop_table('rfid_event')
    op.drop_table('balance_config')
    op.drop_table('rfidreader_config')
    op.drop_table('master_config')
    ### end Alembic commands ###
