From 84b75f7a736640c117c08a3053292a4243b20cff Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 28 May 2026 19:53:19 -0400 Subject: [PATCH] =?UTF-8?q?feat(trash):=20migration=200057=20=E2=80=94=20d?= =?UTF-8?q?eleted=5Fat=20+=20deleted=5Fbatch=5Fid=20on=207=20tables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alembic/versions/0057_soft_delete.py | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 alembic/versions/0057_soft_delete.py diff --git a/alembic/versions/0057_soft_delete.py b/alembic/versions/0057_soft_delete.py new file mode 100644 index 0000000..25767ac --- /dev/null +++ b/alembic/versions/0057_soft_delete.py @@ -0,0 +1,38 @@ +"""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")