"""users table

Revision ID: 3f79f0d8dde4
Revises: 
Create Date: 2021-04-02 16:37:07.392971

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('device_data',
    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.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_device_data_battery'), 'device_data', ['battery'], unique=False)
    op.create_index(op.f('ix_device_data_timestamp'), 'device_data', ['timestamp'], unique=False)
    op.create_table('device',
    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_data_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['device_data_id'], ['device_data.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_device_application_id'), 'device', ['application_id'], unique=False)
    op.create_index(op.f('ix_device_application_name'), 'device', ['application_name'], unique=False)
    op.create_index(op.f('ix_device_description'), 'device', ['description'], unique=False)
    op.create_index(op.f('ix_device_device_EUI'), 'device', ['device_EUI'], unique=True)
    op.create_index(op.f('ix_device_device_name'), 'device', ['device_name'], unique=False)
    op.create_index(op.f('ix_device_device_profile_name'), 'device', ['device_profile_name'], unique=False)
    op.create_index(op.f('ix_device_timestamp'), 'device', ['timestamp'], unique=False)
    op.create_table('user',
    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('device_id', sa.Integer(), nullable=False),
    sa.Column('about_me', sa.String(length=140), nullable=True),
    sa.Column('last_seen', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['device_id'], ['device.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)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    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_index(op.f('ix_device_timestamp'), table_name='device')
    op.drop_index(op.f('ix_device_device_profile_name'), table_name='device')
    op.drop_index(op.f('ix_device_device_name'), table_name='device')
    op.drop_index(op.f('ix_device_device_EUI'), table_name='device')
    op.drop_index(op.f('ix_device_description'), table_name='device')
    op.drop_index(op.f('ix_device_application_name'), table_name='device')
    op.drop_index(op.f('ix_device_application_id'), table_name='device')
    op.drop_table('device')
    op.drop_index(op.f('ix_device_data_timestamp'), table_name='device_data')
    op.drop_index(op.f('ix_device_data_battery'), table_name='device_data')
    op.drop_table('device_data')
    # ### end Alembic commands ###
