49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
"""Communication: folder_id in comm_conversations for folder organization
|
|
|
|
Revision ID: 0140
|
|
Revises: 0139
|
|
Create Date: 2026-08-21
|
|
|
|
Adds folder_id to comm_conversations for folder-based organization.
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects.postgresql import UUID as PGUUID
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = "0140"
|
|
down_revision = "0139"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def _table_exists(conn, table_name: str) -> bool:
|
|
"""True when the table exists (dual-path convergence, Gate B).
|
|
|
|
On a fresh install the kommunikation plugin SQL migration has not run
|
|
yet when Alembic reaches this revision — skip instead of failing.
|
|
The plugin-side migration adds the same column idempotently.
|
|
"""
|
|
row = conn.execute(
|
|
sa.text("SELECT to_regclass(:tname) IS NOT NULL"),
|
|
{"tname": f"public.{table_name}"},
|
|
).scalar()
|
|
return bool(row)
|
|
|
|
|
|
def upgrade() -> None:
|
|
conn = op.get_bind()
|
|
if not _table_exists(conn, "comm_conversations"):
|
|
return
|
|
op.add_column("comm_conversations", sa.Column("folder_id", PGUUID(as_uuid=True), nullable=True))
|
|
op.create_index("ix_comm_conversations_folder", "comm_conversations", ["folder_id"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
conn = op.get_bind()
|
|
if not _table_exists(conn, "comm_conversations"):
|
|
return
|
|
op.drop_index("ix_comm_conversations_folder", table_name="comm_conversations")
|
|
op.drop_column("comm_conversations", "folder_id")
|