11a49eb7fd
Migration files 038-042 were accidentally deleted by commit d2217531
("Sentinel: Fix SSRF in IMAP connections"), which broke container
startup because existing databases had alembic_version stamped to
042_add_file_shares — a revision Alembic could no longer find.
Restored from the parent of that commit:
- 038_add_api_token_expires_at.py
- 039_add_classification_rules.py
- 040_add_automation_hooks.py
- 041_add_document_comments_and_annotations.py
- 042_add_file_shares.py
Alembic now resolves a clean single-head chain (001→042).
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
Agent-Logs-Url: https://github.com/christianlouis/DocuElevate/sessions/f6165a49-2ec0-4158-9f1f-d508bb0489fe
89 lines
4.2 KiB
Python
89 lines
4.2 KiB
Python
"""Add document_comments and document_annotations tables.
|
|
|
|
Revision ID: 041_add_document_comments_and_annotations
|
|
Revises: 040_add_automation_hooks
|
|
Create Date: 2026-03-21
|
|
|
|
"""
|
|
|
|
from typing import Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "041_add_document_comments_and_annotations"
|
|
down_revision: Union[str, None] = "040_add_automation_hooks"
|
|
depends_on: Union[str, None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""Add document_comments and document_annotations tables."""
|
|
conn = op.get_bind()
|
|
inspector = sa.inspect(conn)
|
|
existing_tables = set(inspector.get_table_names())
|
|
|
|
if "document_comments" not in existing_tables:
|
|
op.create_table(
|
|
"document_comments",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("file_id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.String(), nullable=False),
|
|
sa.Column("parent_id", sa.Integer(), nullable=True),
|
|
sa.Column("body", sa.Text(), nullable=False),
|
|
sa.Column("mentions", sa.Text(), nullable=True),
|
|
sa.Column("is_resolved", sa.Boolean(), nullable=False, server_default="0"),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now()),
|
|
sa.ForeignKeyConstraint(["file_id"], ["files.id"]),
|
|
sa.ForeignKeyConstraint(["parent_id"], ["document_comments.id"]),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index("ix_document_comments_id", "document_comments", ["id"])
|
|
op.create_index("ix_document_comments_file_id", "document_comments", ["file_id"])
|
|
op.create_index("ix_document_comments_user_id", "document_comments", ["user_id"])
|
|
op.create_index("ix_document_comments_parent_id", "document_comments", ["parent_id"])
|
|
|
|
if "document_annotations" not in existing_tables:
|
|
op.create_table(
|
|
"document_annotations",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("file_id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.String(), nullable=False),
|
|
sa.Column("page", sa.Integer(), nullable=False),
|
|
sa.Column("x", sa.Float(), nullable=False),
|
|
sa.Column("y", sa.Float(), nullable=False),
|
|
sa.Column("width", sa.Float(), nullable=False),
|
|
sa.Column("height", sa.Float(), nullable=False),
|
|
sa.Column("content", sa.Text(), nullable=False),
|
|
sa.Column("annotation_type", sa.String(50), nullable=False, server_default="note"),
|
|
sa.Column("color", sa.String(20), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now()),
|
|
sa.ForeignKeyConstraint(["file_id"], ["files.id"]),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index("ix_document_annotations_id", "document_annotations", ["id"])
|
|
op.create_index("ix_document_annotations_file_id", "document_annotations", ["file_id"])
|
|
op.create_index("ix_document_annotations_user_id", "document_annotations", ["user_id"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Drop document_comments and document_annotations tables."""
|
|
conn = op.get_bind()
|
|
inspector = sa.inspect(conn)
|
|
existing_tables = set(inspector.get_table_names())
|
|
|
|
if "document_annotations" in existing_tables:
|
|
op.drop_index("ix_document_annotations_user_id", "document_annotations")
|
|
op.drop_index("ix_document_annotations_file_id", "document_annotations")
|
|
op.drop_index("ix_document_annotations_id", "document_annotations")
|
|
op.drop_table("document_annotations")
|
|
|
|
if "document_comments" in existing_tables:
|
|
op.drop_index("ix_document_comments_parent_id", "document_comments")
|
|
op.drop_index("ix_document_comments_user_id", "document_comments")
|
|
op.drop_index("ix_document_comments_file_id", "document_comments")
|
|
op.drop_index("ix_document_comments_id", "document_comments")
|
|
op.drop_table("document_comments")
|