"""empty message

Revision ID: 0fd7f93652f5
Revises: bc31702435eb
Create Date: 2021-04-03 11:01:38.087545

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = '0fd7f93652f5'
down_revision = 'bc31702435eb'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('username', sa.String(length=50), nullable=True),
    sa.Column('email', sa.String(length=120), nullable=True),
    sa.Column('password_hash', sa.String(length=128), nullable=True),
    sa.Column('about_me', sa.String(length=140), nullable=True),
    sa.Column('last_seen', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
    op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
    op.create_table('devices',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('device_EUI', sa.String(length=50), nullable=True),
    sa.Column('device_name', sa.String(length=50), nullable=True),
    sa.Column('description', sa.String(length=100), nullable=True),
    sa.Column('device_profile_name', sa.String(length=50), nullable=True),
    sa.Column('application_id', sa.String(length=50), nullable=True),
    sa.Column('application_name', sa.String(length=50), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('device_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['device_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_devices_application_id'), 'devices', ['application_id'], unique=False)
    op.create_index(op.f('ix_devices_application_name'), 'devices', ['application_name'], unique=False)
    op.create_index(op.f('ix_devices_description'), 'devices', ['description'], unique=False)
    op.create_index(op.f('ix_devices_device_EUI'), 'devices', ['device_EUI'], unique=True)
    op.create_index(op.f('ix_devices_device_name'), 'devices', ['device_name'], unique=False)
    op.create_index(op.f('ix_devices_device_profile_name'), 'devices', ['device_profile_name'], unique=False)
    op.create_index(op.f('ix_devices_timestamp'), 'devices', ['timestamp'], unique=False)
    op.create_table('dates',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('data', sa.String(length=140), nullable=True),
    sa.Column('battery', sa.String(length=50), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('device_data_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['device_data_id'], ['devices.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_dates_battery'), 'dates', ['battery'], unique=False)
    op.create_index(op.f('ix_dates_timestamp'), 'dates', ['timestamp'], unique=False)
    op.drop_index('ix_user_email', table_name='user')
    op.drop_index('ix_user_username', table_name='user')
    op.drop_table('user')
    op.drop_index('ix_device_application_id', table_name='device')
    op.drop_index('ix_device_application_name', table_name='device')
    op.drop_index('ix_device_description', table_name='device')
    op.drop_index('ix_device_device_EUI', table_name='device')
    op.drop_index('ix_device_device_name', table_name='device')
    op.drop_index('ix_device_device_profile_name', table_name='device')
    op.drop_index('ix_device_timestamp', table_name='device')
    op.drop_table('device')
    op.drop_index('ix_device_data_battery', table_name='device_data')
    op.drop_index('ix_device_data_timestamp', table_name='device_data')
    op.drop_table('device_data')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('device_data',
    sa.Column('id', mysql.INTEGER(display_width=11), autoincrement=True, nullable=False),
    sa.Column('data', mysql.VARCHAR(length=140), nullable=True),
    sa.Column('battery', mysql.VARCHAR(length=50), nullable=True),
    sa.Column('timestamp', mysql.DATETIME(), nullable=True),
    sa.Column('device_data_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['device_data_id'], ['device_data.id'], name='device_data_ibfk_1'),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_index('ix_device_data_timestamp', 'device_data', ['timestamp'], unique=False)
    op.create_index('ix_device_data_battery', 'device_data', ['battery'], unique=False)
    op.create_table('device',
    sa.Column('id', mysql.INTEGER(display_width=11), autoincrement=True, nullable=False),
    sa.Column('device_EUI', mysql.VARCHAR(length=50), nullable=True),
    sa.Column('device_name', mysql.VARCHAR(length=50), nullable=True),
    sa.Column('description', mysql.VARCHAR(length=100), nullable=True),
    sa.Column('device_profile_name', mysql.VARCHAR(length=50), nullable=True),
    sa.Column('application_id', mysql.VARCHAR(length=50), nullable=True),
    sa.Column('application_name', mysql.VARCHAR(length=50), nullable=True),
    sa.Column('timestamp', mysql.DATETIME(), nullable=True),
    sa.Column('device_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['device_id'], ['device.id'], name='device_ibfk_1'),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_index('ix_device_timestamp', 'device', ['timestamp'], unique=False)
    op.create_index('ix_device_device_profile_name', 'device', ['device_profile_name'], unique=False)
    op.create_index('ix_device_device_name', 'device', ['device_name'], unique=False)
    op.create_index('ix_device_device_EUI', 'device', ['device_EUI'], unique=True)
    op.create_index('ix_device_description', 'device', ['description'], unique=False)
    op.create_index('ix_device_application_name', 'device', ['application_name'], unique=False)
    op.create_index('ix_device_application_id', 'device', ['application_id'], unique=False)
    op.create_table('user',
    sa.Column('id', mysql.INTEGER(display_width=11), autoincrement=True, nullable=False),
    sa.Column('username', mysql.VARCHAR(length=50), nullable=True),
    sa.Column('email', mysql.VARCHAR(length=120), nullable=True),
    sa.Column('password_hash', mysql.VARCHAR(length=128), nullable=True),
    sa.Column('about_me', mysql.VARCHAR(length=140), nullable=True),
    sa.Column('last_seen', mysql.DATETIME(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_index('ix_user_username', 'user', ['username'], unique=True)
    op.create_index('ix_user_email', 'user', ['email'], unique=True)
    op.drop_index(op.f('ix_dates_timestamp'), table_name='dates')
    op.drop_index(op.f('ix_dates_battery'), table_name='dates')
    op.drop_table('dates')
    op.drop_index(op.f('ix_devices_timestamp'), table_name='devices')
    op.drop_index(op.f('ix_devices_device_profile_name'), table_name='devices')
    op.drop_index(op.f('ix_devices_device_name'), table_name='devices')
    op.drop_index(op.f('ix_devices_device_EUI'), table_name='devices')
    op.drop_index(op.f('ix_devices_description'), table_name='devices')
    op.drop_index(op.f('ix_devices_application_name'), table_name='devices')
    op.drop_index(op.f('ix_devices_application_id'), table_name='devices')
    op.drop_table('devices')
    op.drop_index(op.f('ix_users_username'), table_name='users')
    op.drop_index(op.f('ix_users_email'), table_name='users')
    op.drop_table('users')
    # ### end Alembic commands ###
