feat(database): change alembic number and add idempotency

This commit is contained in:
Anish Sarkar 2026-04-30 16:05:58 +05:30
parent ba2a08b295
commit 1ce122cc99
2 changed files with 72 additions and 63 deletions

View file

@ -1,63 +0,0 @@
"""134_add_thread_auto_model_pinning_fields
Revision ID: 134
Revises: 133
Create Date: 2026-04-29
Add thread-level fields to persist Auto (Fastest) model pinning metadata:
- pinned_llm_config_id: concrete resolved config id used for this thread
- pinned_auto_mode: auto policy identifier (currently "auto_fastest")
- pinned_at: timestamp when the pin was created/refreshed
"""
from __future__ import annotations
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "134"
down_revision: str | None = "133"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
op.add_column(
"new_chat_threads",
sa.Column("pinned_llm_config_id", sa.Integer(), nullable=True),
)
op.add_column(
"new_chat_threads",
sa.Column("pinned_auto_mode", sa.String(length=32), nullable=True),
)
op.add_column(
"new_chat_threads",
sa.Column("pinned_at", sa.TIMESTAMP(timezone=True), nullable=True),
)
op.create_index(
"ix_new_chat_threads_pinned_llm_config_id",
"new_chat_threads",
["pinned_llm_config_id"],
unique=False,
)
op.create_index(
"ix_new_chat_threads_pinned_auto_mode",
"new_chat_threads",
["pinned_auto_mode"],
unique=False,
)
def downgrade() -> None:
op.drop_index("ix_new_chat_threads_pinned_auto_mode", table_name="new_chat_threads")
op.drop_index(
"ix_new_chat_threads_pinned_llm_config_id", table_name="new_chat_threads"
)
op.drop_column("new_chat_threads", "pinned_at")
op.drop_column("new_chat_threads", "pinned_auto_mode")
op.drop_column("new_chat_threads", "pinned_llm_config_id")

View file

@ -0,0 +1,72 @@
"""138_add_thread_auto_model_pinning_fields
Revision ID: 138
Revises: 137
Create Date: 2026-04-30
Add thread-level fields to persist Auto (Fastest) model pinning metadata:
- pinned_llm_config_id: concrete resolved config id used for this thread
- pinned_auto_mode: auto policy identifier (currently "auto_fastest")
- pinned_at: timestamp when the pin was created/refreshed
Idempotent: this migration was originally numbered 134 on the
``feat/split-auto-free-premium`` branch and was renumbered to 138 during
the merge with ``upstream/dev`` (which claimed 134-137). Some databases
already have these columns/indexes from when the original 134 ran, so we
use ``IF NOT EXISTS`` to make re-application a no-op for those DBs while
still creating the schema on fresh databases.
"""
from __future__ import annotations
from collections.abc import Sequence
from alembic import op
revision: str = "138"
down_revision: str | None = "137"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
op.execute(
"ALTER TABLE new_chat_threads "
"ADD COLUMN IF NOT EXISTS pinned_llm_config_id INTEGER"
)
op.execute(
"ALTER TABLE new_chat_threads "
"ADD COLUMN IF NOT EXISTS pinned_auto_mode VARCHAR(32)"
)
op.execute(
"ALTER TABLE new_chat_threads "
"ADD COLUMN IF NOT EXISTS pinned_at TIMESTAMP WITH TIME ZONE"
)
op.execute(
"CREATE INDEX IF NOT EXISTS ix_new_chat_threads_pinned_llm_config_id "
"ON new_chat_threads (pinned_llm_config_id)"
)
op.execute(
"CREATE INDEX IF NOT EXISTS ix_new_chat_threads_pinned_auto_mode "
"ON new_chat_threads (pinned_auto_mode)"
)
def downgrade() -> None:
op.execute(
"DROP INDEX IF EXISTS ix_new_chat_threads_pinned_auto_mode"
)
op.execute(
"DROP INDEX IF EXISTS ix_new_chat_threads_pinned_llm_config_id"
)
op.execute(
"ALTER TABLE new_chat_threads DROP COLUMN IF EXISTS pinned_at"
)
op.execute(
"ALTER TABLE new_chat_threads DROP COLUMN IF EXISTS pinned_auto_mode"
)
op.execute(
"ALTER TABLE new_chat_threads DROP COLUMN IF EXISTS pinned_llm_config_id"
)