87 lines
2.8 KiB
Python
87 lines
2.8 KiB
Python
"""Durable profile, ModelForge route, and Qdrant collection selection.
|
|
|
|
Revision ID: 0021_embedding_selection
|
|
Revises: 0020_source_sync_schedule
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision = "0021_embedding_selection"
|
|
down_revision = "0020_source_sync_schedule"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"embedding_selection_state",
|
|
sa.Column("singleton_id", sa.Integer(), primary_key=True),
|
|
sa.Column("generation", sa.Integer(), nullable=False),
|
|
sa.Column("initialized", sa.Boolean(), nullable=False),
|
|
sa.Column("active_selection", sa.JSON(), nullable=True),
|
|
sa.Column("previous_selection", sa.JSON(), nullable=True),
|
|
sa.Column(
|
|
"updated_at",
|
|
sa.DateTime(timezone=True),
|
|
nullable=False,
|
|
server_default=sa.func.now(),
|
|
),
|
|
schema="profiles",
|
|
)
|
|
op.create_table(
|
|
"embedding_selection_operations",
|
|
sa.Column("operation_id", sa.Uuid(as_uuid=True), primary_key=True),
|
|
sa.Column("action", sa.String(length=16), nullable=False),
|
|
sa.Column("expected_generation", sa.Integer(), nullable=False),
|
|
sa.Column("request_fingerprint", sa.String(length=64), nullable=False),
|
|
sa.Column("result_generation", sa.Integer(), nullable=False),
|
|
sa.Column("result_selection", sa.JSON(), nullable=False),
|
|
sa.Column(
|
|
"operation_evidence",
|
|
sa.JSON(),
|
|
nullable=False,
|
|
server_default=sa.text("'{}'::json"),
|
|
),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
schema="profiles",
|
|
)
|
|
op.create_index(
|
|
"ix_profiles_embedding_selection_operations_created_at",
|
|
"embedding_selection_operations",
|
|
["created_at"],
|
|
schema="profiles",
|
|
)
|
|
op.bulk_insert(
|
|
sa.table(
|
|
"embedding_selection_state",
|
|
sa.Column("singleton_id", sa.Integer()),
|
|
sa.Column("generation", sa.Integer()),
|
|
sa.Column("initialized", sa.Boolean()),
|
|
sa.Column("active_selection", sa.JSON()),
|
|
sa.Column("previous_selection", sa.JSON()),
|
|
schema="profiles",
|
|
),
|
|
[
|
|
{
|
|
"singleton_id": 1,
|
|
"generation": 0,
|
|
"initialized": False,
|
|
"active_selection": None,
|
|
"previous_selection": None,
|
|
}
|
|
],
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(
|
|
"ix_profiles_embedding_selection_operations_created_at",
|
|
table_name="embedding_selection_operations",
|
|
schema="profiles",
|
|
)
|
|
op.drop_table("embedding_selection_operations", schema="profiles")
|
|
op.drop_table("embedding_selection_state", schema="profiles")
|