"""housekeeping: remove shift requirement, simplify foto tipe

Revision ID: a1b2c3d4e5f6
Revises: z2d3e4f5g6h7
Create Date: 2026-04-14

"""
from alembic import op
import sqlalchemy as sa

revision = 'hk01_no_shift_tipe'
down_revision = 'd450ca7deee2'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # 1. Drop old unique constraint (spbu_id, shift_id, tanggal)
    op.drop_constraint('uq_housekeeping', 'housekeeping', type_='unique')

    # 2. Make shift_id nullable
    op.alter_column('housekeeping', 'shift_id', nullable=True)

    # 3. New unique constraint: (spbu_id, tanggal) only
    op.create_unique_constraint('uq_housekeeping_tanggal', 'housekeeping', ['spbu_id', 'tanggal'])

    # 4. Set all existing tipe values to 'foto'
    op.execute("UPDATE housekeeping_foto SET tipe = 'foto'")


def downgrade() -> None:
    op.drop_constraint('uq_housekeeping_tanggal', 'housekeeping', type_='unique')
    op.alter_column('housekeeping', 'shift_id', nullable=False)
    op.create_unique_constraint('uq_housekeeping', 'housekeeping', ['spbu_id', 'shift_id', 'tanggal'])
