"""soft-delete: deleted_at + deleted_batch_id on 7 tables

Revision ID: 0057
Revises: 0056
Create Date: 2026-05-28

Recoverable deletes: each soft-deletable table gains a nullable deleted_at
timestamp (NULL = live) and a deleted_batch_id (text UUID) stamped per delete
operation so a cascaded delete restores as a unit. A daily cron purges rows
past the retention window.
"""
from alembic import op
import sqlalchemy as sa


revision = "0057"
down_revision = "0056"
branch_labels = None
depends_on = None

_TABLES = (
    "notes", "events", "projects", "milestones",
    "rulebooks", "rulebook_topics", "rules",
)


def upgrade() -> None:
    for t in _TABLES:
        op.add_column(t, sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True))
        op.add_column(t, sa.Column("deleted_batch_id", sa.Text(), nullable=True))
        op.create_index(f"ix_{t}_deleted_at", t, ["deleted_at"])


def downgrade() -> None:
    for t in reversed(_TABLES):
        op.drop_index(f"ix_{t}_deleted_at", table_name=t)
        op.drop_column(t, "deleted_batch_id")
        op.drop_column(t, "deleted_at")
