Files
leocrm/alembic/versions/0038_dms_content_hash.py
T
Agent Zero 727d86614e Security fixes: P0-P2 complete (22 fixes)
P0 (7): Auth-bypass removed, migrations fixed, plugin-upload disabled, RLS FORCE+WITH CHECK, plugin double-registration fixed, persistent volume, domain removed
P1 (11): User/tenant model, Redis centralized, worker separated, transactional outbox, XSS fixed, DMS chunked streaming, permissions unified, password reset, metrics secured, config/docs fixed, cross-tenant FK
P2 (4): Contact model normalized, cross-imports reduced 94%, commands+state machines for contacts/dms/mail/calendar, SPA path-traversal

8 new migrations, 99 unit tests, 13 commands, 8 contracts, 72 files changed
2026-07-25 21:03:46 +02:00

45 lines
1.2 KiB
Python

"""Add content_hash column to files table for SHA-256 dedup and integrity.
Revision ID: 0038_dms_content_hash
Revises: 0037_user_tenant_model
Create Date: 2026-07-25
Changes:
1. Add content_hash (String(64), nullable) column to files table.
"""
from __future__ import annotations
from typing import Union
import sqlalchemy as sa
from alembic import op
# revision identifiers
revision: str = "0038_dms_content_hash"
down_revision: Union[str, None] = "0037_user_tenant_model"
branch_labels: Union[str, None] = None
depends_on: Union[str, None] = None
def _column_exists(table: str, column: str) -> str:
"""Return SQL that checks if a column exists on a table."""
return (
f"SELECT 1 FROM information_schema.columns "
f"WHERE table_name = '{table}' AND column_name = '{column}'"
)
def upgrade() -> None:
conn = op.get_bind()
result = conn.execute(sa.text(_column_exists("files", "content_hash"))).fetchone()
if result is None:
op.add_column("files", sa.Column("content_hash", sa.String(64), nullable=True))
def downgrade() -> None:
conn = op.get_bind()
result = conn.execute(sa.text(_column_exists("files", "content_hash"))).fetchone()
if result is not None:
op.drop_column("files", "content_hash")