From 432649080f31cdd7cca859d112c789b9c57f839d Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Sat, 4 Jul 2026 00:31:47 +0000 Subject: [PATCH] feat(core): add alembic migration for soft-delete columns on core tables --- alembic/versions/0012_soft_delete.py | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 alembic/versions/0012_soft_delete.py diff --git a/alembic/versions/0012_soft_delete.py b/alembic/versions/0012_soft_delete.py new file mode 100644 index 0000000..fcf901f --- /dev/null +++ b/alembic/versions/0012_soft_delete.py @@ -0,0 +1,47 @@ +"""Add deleted_at column to core tables that don't have it yet. + +Revision ID: 0012_soft_delete +Revises: 0011_attachments +Create Date: 2026-07-04 +""" + +from __future__ import annotations + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + +revision: str = "0012_soft_delete" +down_revision: Union[str, None] = "0011_attachments" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + +# Core tables that need deleted_at added +# Excludes: audit_log (immutable), deletion_log (already has it), +# tenants (top-level), user_tenants (join table with cascade delete) +TABLES_NEEDING_SOFT_DELETE = [ + "users", + "roles", + "sessions", + "notifications", + "ai_conversations", + "ai_messages", + "workflows", + "workflow_instances", + "workflow_step_history", + "company_contacts", +] + + +def upgrade() -> None: + for table_name in TABLES_NEEDING_SOFT_DELETE: + op.add_column( + table_name, + sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True), + ) + + +def downgrade() -> None: + for table_name in reversed(TABLES_NEEDING_SOFT_DELETE): + op.drop_column(table_name, "deleted_at")