"""create house and area table

Revision ID: 7ef4aef5fcda
Revises: 4b90a6ac504b
Create Date: 2024-06-25 09:20:59.915212

"""
from typing import Sequence, Union

import backend.db.migration_types
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '7ef4aef5fcda'
down_revision: Union[str, None] = '4b90a6ac504b'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('houses',
    sa.Column('id', backend.db.models.guid.GUID(), nullable=False),
    sa.Column('icon', sa.String(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('address', sa.String(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_houses_address'), 'houses', ['address'], unique=False)
    op.create_index(op.f('ix_houses_created_at'), 'houses', ['created_at'], unique=False)
    op.create_index(op.f('ix_houses_icon'), 'houses', ['icon'], unique=False)
    op.create_index(op.f('ix_houses_id'), 'houses', ['id'], unique=False)
    op.create_index(op.f('ix_houses_name'), 'houses', ['name'], unique=False)
    op.create_table('areas',
    sa.Column('id', backend.db.models.guid.GUID(), nullable=False),
    sa.Column('house_id', backend.db.models.guid.GUID(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('desc', sa.String(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['house_id'], ['houses.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_areas_created_at'), 'areas', ['created_at'], unique=False)
    op.create_index(op.f('ix_areas_desc'), 'areas', ['desc'], unique=False)
    op.create_index(op.f('ix_areas_house_id'), 'areas', ['house_id'], unique=False)
    op.create_index(op.f('ix_areas_id'), 'areas', ['id'], unique=False)
    op.create_index(op.f('ix_areas_name'), 'areas', ['name'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_areas_name'), table_name='areas')
    op.drop_index(op.f('ix_areas_id'), table_name='areas')
    op.drop_index(op.f('ix_areas_house_id'), table_name='areas')
    op.drop_index(op.f('ix_areas_desc'), table_name='areas')
    op.drop_index(op.f('ix_areas_created_at'), table_name='areas')
    op.drop_table('areas')
    op.drop_index(op.f('ix_houses_name'), table_name='houses')
    op.drop_index(op.f('ix_houses_id'), table_name='houses')
    op.drop_index(op.f('ix_houses_icon'), table_name='houses')
    op.drop_index(op.f('ix_houses_created_at'), table_name='houses')
    op.drop_index(op.f('ix_houses_address'), table_name='houses')
    op.drop_table('houses')
    # ### end Alembic commands ###
