"""add reconciled_at + reconciled_by_id to laporan_shift, stock_adjustment, penerimaan

Revision ID: h4i5j6k7l8m9
Revises: g3h4i5j6k7l8
Create Date: 2026-05-09
"""
from alembic import op
import sqlalchemy as sa

revision = 'h4i5j6k7l8m9'
down_revision = 'g3h4i5j6k7l8'
branch_labels = None
depends_on = None


def upgrade() -> None:
    for table in ('laporan_shift', 'stock_adjustment', 'penerimaan'):
        op.add_column(table, sa.Column('reconciled_at', sa.DateTime(timezone=True), nullable=True))
        op.add_column(table, sa.Column('reconciled_by_id', sa.Integer(), nullable=True))
        op.create_foreign_key(
            f'fk_{table}_reconciled_by',
            table, 'master_user',
            ['reconciled_by_id'], ['id'],
            ondelete='SET NULL',
        )


def downgrade() -> None:
    for table in ('laporan_shift', 'stock_adjustment', 'penerimaan'):
        op.drop_constraint(f'fk_{table}_reconciled_by', table, type_='foreignkey')
        op.drop_column(table, 'reconciled_by_id')
        op.drop_column(table, 'reconciled_at')
