"""Ajoute l'historique d'occupation des logements.

Revision ID: c0d4e5f6a7b8
Revises: b9c3d4e5f6a7
"""
from alembic import op
import sqlalchemy as sa

revision = "c0d4e5f6a7b8"
down_revision = "b9c3d4e5f6a7"
branch_labels = None
depends_on = None

def upgrade():
    op.create_table(
        "housing_occupancies",
        sa.Column("id", sa.Integer(), primary_key=True),
        sa.Column("housing_unit_id", sa.Integer(), sa.ForeignKey("housing_units.id", ondelete="CASCADE"), nullable=False),
        sa.Column("occupant_name", sa.String(150), nullable=False),
        sa.Column("occupant_contact", sa.String(150)),
        sa.Column("start_date", sa.Date(), nullable=False),
        sa.Column("end_date", sa.Date()),
        sa.Column("key_count", sa.Integer(), nullable=False, server_default="0"),
        sa.Column("entry_condition", sa.Text()),
        sa.Column("exit_condition", sa.Text()),
        sa.Column("notes", sa.Text()),
        sa.Column("created_at", sa.DateTime()),
    )
    op.create_index("ix_housing_occupancies_housing_unit_id", "housing_occupancies", ["housing_unit_id"])

def downgrade():
    op.drop_table("housing_occupancies")
