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
59 lines
2.2 KiB
Python
59 lines
2.2 KiB
Python
"""Add file_shares table for per-user document sharing and role-based access.
|
|
|
|
Revision ID: 042_add_file_shares
|
|
Revises: 041_add_document_comments_and_annotations
|
|
Create Date: 2026-03-22
|
|
|
|
"""
|
|
|
|
from typing import Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "042_add_file_shares"
|
|
down_revision: Union[str, None] = "041_add_document_comments_and_annotations"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""Create file_shares table."""
|
|
conn = op.get_bind()
|
|
inspector = sa.inspect(conn)
|
|
existing_tables = set(inspector.get_table_names())
|
|
|
|
if "file_shares" not in existing_tables:
|
|
op.create_table(
|
|
"file_shares",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("file_id", sa.Integer(), nullable=False),
|
|
sa.Column("owner_id", sa.String(), nullable=False),
|
|
sa.Column("shared_with_user_id", sa.String(), nullable=False),
|
|
sa.Column("role", sa.String(20), nullable=False, server_default="viewer"),
|
|
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"),
|
|
sa.UniqueConstraint("file_id", "shared_with_user_id", name="uq_file_share_file_user"),
|
|
)
|
|
op.create_index("ix_file_shares_id", "file_shares", ["id"])
|
|
op.create_index("ix_file_shares_file_id", "file_shares", ["file_id"])
|
|
op.create_index("ix_file_shares_owner_id", "file_shares", ["owner_id"])
|
|
op.create_index("ix_file_shares_shared_with_user_id", "file_shares", ["shared_with_user_id"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Drop file_shares table."""
|
|
op.drop_index("ix_file_shares_shared_with_user_id", table_name="file_shares")
|
|
op.drop_index("ix_file_shares_owner_id", table_name="file_shares")
|
|
op.drop_index("ix_file_shares_file_id", table_name="file_shares")
|
|
op.drop_index("ix_file_shares_id", table_name="file_shares")
|
|
op.drop_table("file_shares")
|