make migration idempotent

This commit is contained in:
CREDO23 2026-01-23 20:00:18 +02:00
parent a627cc709e
commit 68dc7723af

View file

@ -43,7 +43,7 @@ def upgrade() -> None:
# Add unique partial index on public_share_token (only non-null values)
op.execute(
"""
CREATE UNIQUE INDEX ix_new_chat_threads_public_share_token
CREATE UNIQUE INDEX IF NOT EXISTS ix_new_chat_threads_public_share_token
ON new_chat_threads(public_share_token)
WHERE public_share_token IS NOT NULL
"""
@ -52,7 +52,7 @@ def upgrade() -> None:
# Add partial index on public_share_enabled for fast public chat queries
op.execute(
"""
CREATE INDEX ix_new_chat_threads_public_share_enabled
CREATE INDEX IF NOT EXISTS ix_new_chat_threads_public_share_enabled
ON new_chat_threads(public_share_enabled)
WHERE public_share_enabled = TRUE
"""
@ -61,11 +61,7 @@ def upgrade() -> None:
def downgrade() -> None:
"""Remove public sharing columns from new_chat_threads."""
op.drop_index(
"ix_new_chat_threads_public_share_enabled", table_name="new_chat_threads"
)
op.drop_index(
"ix_new_chat_threads_public_share_token", table_name="new_chat_threads"
)
op.execute("DROP INDEX IF EXISTS ix_new_chat_threads_public_share_enabled")
op.execute("DROP INDEX IF EXISTS ix_new_chat_threads_public_share_token")
op.drop_column("new_chat_threads", "public_share_enabled")
op.drop_column("new_chat_threads", "public_share_token")