# pylint: skip-file

"""empty message

Revision ID: da6dacc30330
Revises: <PASSWORD>
Create Date: 2019-09-20 18:29:01.864665

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'da<PASSWORD>'
down_revision = '<PASSWORD>'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('device_group',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('password', sa.String(length=255), nullable=False),
    sa.Column('product_key', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('product_key')
    )
    op.create_table('user',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('username', sa.String(length=255), nullable=True),
    sa.Column('email', sa.String(length=255), nullable=False),
    sa.Column('registered_on', sa.DateTime(), nullable=False),
    sa.Column('is_admin', sa.Boolean(), nullable=False),
    sa.Column('password', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email'),
    sa.UniqueConstraint('username')
    )
    op.create_table('executive_type',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('state_type', sa.Enum('Boolean', 'Enum', 'Decimal', name='state_type'), nullable=False),
    sa.Column('state_range_min', sa.Float(), nullable=False),
    sa.Column('state_range_max', sa.Float(), nullable=False),
    sa.Column('device_group_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['device_group_id'], ['device_group.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('log',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('type', sa.Enum('Debug', 'Error', 'Info', name='log_type'), nullable=False),
    sa.Column('error_message', sa.String(length=255), nullable=True),
    sa.Column('stack_trace', sa.String(length=255), nullable=True),
    sa.Column('payload', sa.String(length=255), nullable=True),
    sa.Column('time', sa.Integer(), nullable=True),
    sa.Column('creation_date', sa.DateTime(), nullable=False),
    sa.Column('device_group_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['device_group_id'], ['device_group.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('sensor_type',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('reading_type', sa.Enum('Boolean', 'Enum', 'Decimal', name='reading_type'), nullable=False),
    sa.Column('range_min', sa.Float(), nullable=False),
    sa.Column('range_max', sa.Float(), nullable=False),
    sa.Column('device_group_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['device_group_id'], ['device_group.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('unconfigured_device',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('device_key', sa.String(length=255), nullable=False),
    sa.Column('password', sa.String(length=255), nullable=False),
    sa.Column('device_group_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['device_group_id'], ['device_group.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('device_key')
    )
    op.create_table('user_group',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('password', sa.String(length=255), nullable=False),
    sa.Column('device_group_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['device_group_id'], ['device_group.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('enumerator_value',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('number', sa.Integer(), nullable=False),
    sa.Column('text', sa.String(length=255), nullable=False),
    sa.Column('sensor_type_id', sa.Integer(), nullable=False),
    sa.Column('executive_type_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['executive_type_id'], ['executive_type.id'], ),
    sa.ForeignKeyConstraint(['sensor_type_id'], ['sensor_type.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('formula',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('rule', sa.String(length=255), nullable=False),
    sa.Column('user_group_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['user_group_id'], ['user_group.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('sensor',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('is_updated', sa.Boolean(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('is_assigned', sa.Boolean(), nullable=False),
    sa.Column('device_key', sa.String(length=255), nullable=False),
    sa.Column('sensor_type_id', sa.Integer(), nullable=False),
    sa.Column('user_group_id', sa.Integer(), nullable=True),
    sa.Column('device_group_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['device_group_id'], ['device_group.id'], ),
    sa.ForeignKeyConstraint(['sensor_type_id'], ['sensor_type.id'], ),
    sa.ForeignKeyConstraint(['user_group_id'], ['user_group.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('device_key')
    )
    op.create_table('user_group_member',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('user_group_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['user_group_id'], ['user_group.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('user_id', 'user_group_id')
    )
    op.create_table('executive_device',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('state', sa.String(length=255), nullable=False),
    sa.Column('is_updated', sa.Boolean(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('is_assigned', sa.Boolean(), nullable=False),
    sa.Column('positive_state', sa.String(length=255), nullable=True),
    sa.Column('negative_state', sa.String(length=255), nullable=True),
    sa.Column('device_key', sa.String(length=255), nullable=False),
    sa.Column('executive_type_id', sa.Integer(), nullable=False),
    sa.Column('device_group_id', sa.Integer(), nullable=False),
    sa.Column('user_group_id', sa.Integer(), nullable=True),
    sa.Column('formula_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['device_group_id'], ['device_group.id'], ),
    sa.ForeignKeyConstraint(['executive_type_id'], ['executive_type.id'], ),
    sa.ForeignKeyConstraint(['formula_id'], ['formula.id'], ),
    sa.ForeignKeyConstraint(['user_group_id'], ['user_group.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('device_key')
    )
    op.create_table('sensor_reading',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('value', sa.Float(), nullable=False),
    sa.Column('sensor_id', sa.Integer(), nullable=False),
    sa.Column('sensor_type_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['sensor_id'], ['sensor.id'], ),
    sa.ForeignKeyConstraint(['sensor_type_id'], ['sensor_type.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('sensor_reading')
    op.drop_table('executive_device')
    op.drop_table('user_group_member')
    op.drop_table('sensor')
    op.drop_table('formula')
    op.drop_table('enumerator_value')
    op.drop_table('user_group')
    op.drop_table('unconfigured_device')
    op.drop_table('sensor_type')
    op.drop_table('log')
    op.drop_table('executive_type')
    op.drop_table('user')
    op.drop_table('device_group')
    # ### end Alembic commands ###
