sync update from LAN repo (source dhk-1 @ 3b1ec5b4)
This commit is contained in:
1 parent
da6521b6cb
commit
264e2200d6
995 files changed
+148105
-13399
No files matched your search
+5
-9
@@ -9,14 +9,13 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from logging.config import fileConfig
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
|
||||
from deerflow.persistence.base import Base
|
||||
from deerflow.persistence.migration_utils import configure_mysql_migration_lock_waits
|
||||
|
||||
# Import all models so metadata is populated.
|
||||
try:
|
||||
@@ -54,13 +53,10 @@ def do_run_migrations(connection):
|
||||
# = 1 year; innodb_lock_wait_timeout = 50s). Without this, an idle
|
||||
# transaction on another connection can freeze startup indefinitely.
|
||||
# Tunable via DEER_FLOW_ALEMBIC_LOCK_WAIT (seconds, default 15).
|
||||
if connection.dialect.name == "mysql":
|
||||
try:
|
||||
lock_wait = int(os.getenv("DEER_FLOW_ALEMBIC_LOCK_WAIT", "15"))
|
||||
except ValueError:
|
||||
lock_wait = 15
|
||||
connection.execute(text(f"SET SESSION lock_wait_timeout = {lock_wait}"))
|
||||
connection.execute(text(f"SET SESSION innodb_lock_wait_timeout = {lock_wait}"))
|
||||
from deerflow.persistence.gauss_mysql_compat import is_gauss_mysql_product
|
||||
|
||||
if connection.dialect.name == "mysql" and not is_gauss_mysql_product():
|
||||
configure_mysql_migration_lock_waits(connection)
|
||||
|
||||
context.configure(
|
||||
connection=connection,
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
"""Persist DeerFlow-owned fixed parent directories for LLMWiki mappings.
|
||||
|
||||
Revision ID: 20261006_01
|
||||
Revises: 20260920_02
|
||||
Create Date: 2026-10-06
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from deerflow.persistence.types import PortableJSON
|
||||
|
||||
revision = "20261006_01"
|
||||
down_revision = "20260920_02"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "llmwiki_knowledge_bases"
|
||||
_COLUMN = "wiki_parent_directories"
|
||||
|
||||
|
||||
def _columns() -> set[str]:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if not inspector.has_table(_TABLE):
|
||||
return set()
|
||||
return {str(column["name"]) for column in inspector.get_columns(_TABLE)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
columns = _columns()
|
||||
if columns and _COLUMN not in columns:
|
||||
op.add_column(_TABLE, sa.Column(_COLUMN, PortableJSON(), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _COLUMN in _columns():
|
||||
op.drop_column(_TABLE, _COLUMN)
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
"""Persist administrator-managed per-model runtime capabilities.
|
||||
|
||||
Revision ID: 20261009_01
|
||||
Revises: 20261006_01
|
||||
Create Date: 2026-10-09
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "20261009_01"
|
||||
down_revision = "20261006_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "model_capabilities"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if sa.inspect(op.get_bind()).has_table(_TABLE):
|
||||
return
|
||||
op.create_table(
|
||||
_TABLE,
|
||||
sa.Column("model_name", sa.String(length=160), primary_key=True),
|
||||
sa.Column(
|
||||
"supports_reasoning_effort",
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
server_default=sa.false(),
|
||||
),
|
||||
sa.Column("updated_by", sa.String(length=64), nullable=True),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if sa.inspect(op.get_bind()).has_table(_TABLE):
|
||||
op.drop_table(_TABLE)
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
"""Persist the global ordinary-knowledge smart-reasoning switch.
|
||||
|
||||
Revision ID: 20261014_01
|
||||
Revises: 20261009_01
|
||||
Create Date: 2026-10-14
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "20261014_01"
|
||||
down_revision = "20261009_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "knowledge_retrieval_settings"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if sa.inspect(op.get_bind()).has_table(_TABLE):
|
||||
return
|
||||
op.create_table(
|
||||
_TABLE,
|
||||
sa.Column("scope", sa.String(length=64), primary_key=True),
|
||||
sa.Column(
|
||||
"smart_reasoning_enabled",
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
server_default=sa.false(),
|
||||
),
|
||||
sa.Column("revision", sa.Integer(), nullable=False, server_default="1"),
|
||||
sa.Column("updated_by", sa.String(length=64), nullable=True),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if sa.inspect(op.get_bind()).has_table(_TABLE):
|
||||
op.drop_table(_TABLE)
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
"""Persist hierarchical Wiki generation configuration.
|
||||
|
||||
Revision ID: 20261014_02
|
||||
Revises: 20261014_01
|
||||
Create Date: 2026-10-14
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from deerflow.persistence.types import PortableJSON
|
||||
|
||||
revision = "20261014_02"
|
||||
down_revision = "20261014_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "llmwiki_knowledge_bases"
|
||||
_COLUMNS: tuple[sa.Column, ...] = (
|
||||
sa.Column("wiki_directory_paths", PortableJSON(), nullable=True),
|
||||
sa.Column("wiki_focus_instructions", sa.Text(), nullable=True),
|
||||
sa.Column("wiki_content_instructions_raw", sa.Text(), nullable=True),
|
||||
sa.Column("wiki_extraction_instructions_raw", sa.Text(), nullable=True),
|
||||
sa.Column("wiki_generation_managed", sa.Boolean(), nullable=True),
|
||||
sa.Column("wiki_config_schema_version", sa.Integer(), nullable=True),
|
||||
sa.Column("wiki_config_revision", sa.Integer(), nullable=True),
|
||||
sa.Column("wiki_config_apply_status", sa.String(length=32), nullable=True),
|
||||
sa.Column("wiki_config_apply_error", sa.Text(), nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def _columns() -> set[str]:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if not inspector.has_table(_TABLE):
|
||||
return set()
|
||||
return {str(column["name"]) for column in inspector.get_columns(_TABLE)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
existing = _columns()
|
||||
if not existing:
|
||||
return
|
||||
for column in _COLUMNS:
|
||||
if column.name not in existing:
|
||||
op.add_column(_TABLE, column)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
existing = _columns()
|
||||
for column in reversed(_COLUMNS):
|
||||
if column.name in existing:
|
||||
op.drop_column(_TABLE, column.name)
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
"""Persist the knowledge-management advanced-entry switch.
|
||||
|
||||
Revision ID: 20261020_01
|
||||
Revises: 20261019_01, 20261014_02
|
||||
Create Date: 2026-10-20
|
||||
|
||||
An earlier release accidentally reused revision ``20261019_01`` for this
|
||||
column and for the task deep-link table. A database that ran the column
|
||||
migration can therefore report the task migration as applied even though its
|
||||
table is absent. The upgrade reconciles that table and its scope index before
|
||||
ensuring the advanced-management column, so both fresh and affected databases
|
||||
converge on the same schema. The task objects belong to the parent revision and
|
||||
are intentionally left intact by this revision's downgrade.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "20261020_01"
|
||||
down_revision = ("20261019_01", "20261014_02")
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "knowledge_retrieval_settings"
|
||||
_COLUMN = "advanced_management_enabled"
|
||||
_TASK_TABLE = "task_deeplink_threads"
|
||||
_TASK_INDEX = "ix_task_deeplink_threads_scope"
|
||||
|
||||
|
||||
def _columns() -> set[str]:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if not inspector.has_table(_TABLE):
|
||||
return set()
|
||||
return {str(column["name"]) for column in inspector.get_columns(_TABLE)}
|
||||
|
||||
|
||||
def _ensure_task_deeplink_schema() -> None:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if not inspector.has_table(_TASK_TABLE):
|
||||
op.create_table(
|
||||
_TASK_TABLE,
|
||||
sa.Column("thread_id", sa.String(64), primary_key=True),
|
||||
sa.Column("task_id", sa.String(128), nullable=False),
|
||||
sa.Column("source_task_id", sa.String(128), nullable=False),
|
||||
sa.Column("go_path", sa.String(16), nullable=False),
|
||||
sa.Column("agent_id", sa.String(128), nullable=True),
|
||||
sa.Column("created_by", sa.String(64), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
)
|
||||
op.create_index(
|
||||
_TASK_INDEX,
|
||||
_TASK_TABLE,
|
||||
["task_id", "go_path", "updated_at", "thread_id"],
|
||||
)
|
||||
return
|
||||
|
||||
indexes = {
|
||||
str(index["name"])
|
||||
for index in inspector.get_indexes(_TASK_TABLE)
|
||||
if index.get("name")
|
||||
}
|
||||
if _TASK_INDEX not in indexes:
|
||||
op.create_index(
|
||||
_TASK_INDEX,
|
||||
_TASK_TABLE,
|
||||
["task_id", "go_path", "updated_at", "thread_id"],
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
_ensure_task_deeplink_schema()
|
||||
if _COLUMN in _columns():
|
||||
return
|
||||
op.add_column(
|
||||
_TABLE,
|
||||
sa.Column(
|
||||
_COLUMN,
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
server_default=sa.false(),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _COLUMN in _columns():
|
||||
op.drop_column(_TABLE, _COLUMN)
|
||||
+11
-4
@@ -1,8 +1,15 @@
|
||||
"""Add snapshots supplied to the b5-1 task-analysis deep link.
|
||||
|
||||
Revision ID: 20261020_01
|
||||
Revises: 20261019_01
|
||||
Revision ID: 20261021_01
|
||||
Revises: 20261020_01
|
||||
Create Date: 2026-10-20
|
||||
|
||||
This file originally shipped with revision id ``20261020_01`` — the same id as
|
||||
``20261020_01_knowledge_management_advanced_tools`` — which left the migration
|
||||
graph with a duplicate revision and no single head. Re-issued as
|
||||
``20261021_01`` chained after the canonical ``20261020_01``; its upgrade is
|
||||
fully guarded (``if _has_table(): return``) so databases that already created
|
||||
the table under the old id re-run it as a no-op.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -11,8 +18,8 @@ import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261020_01"
|
||||
down_revision = "20261019_01"
|
||||
revision = "20261021_01"
|
||||
down_revision = "20261020_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
"""Admin catalog switch: ``agents.hidden``.
|
||||
|
||||
Hidden agents disappear from every non-admin listing surface (gallery / 我的 /
|
||||
广场 / homepage selector / private square) while staying fully usable — only
|
||||
the admin agents console (?admin=true) keeps listing them.
|
||||
|
||||
The Gateway's startup ORM-column sweep also adds this column on existing
|
||||
databases (Alembic auto-upgrade is disabled there), so this migration mostly
|
||||
serves environments that run Alembic manually. Fully guarded and idempotent.
|
||||
|
||||
Revision ID: 20261022_03
|
||||
Revises: 20261021_01
|
||||
Create Date: 2026-10-22
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261022_03"
|
||||
down_revision = "20261021_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "agents"
|
||||
_COLUMN = "hidden"
|
||||
_INDEX = "ix_agents_hidden"
|
||||
|
||||
|
||||
def _has_table(table_name: str) -> bool:
|
||||
return table_name in inspect(op.get_bind()).get_table_names()
|
||||
|
||||
|
||||
def _has_column(table_name: str, column_name: str) -> bool:
|
||||
if not _has_table(table_name):
|
||||
return False
|
||||
inspector = inspect(op.get_bind())
|
||||
return any(col["name"] == column_name for col in inspector.get_columns(table_name))
|
||||
|
||||
|
||||
def _has_index(table_name: str, index_name: str) -> bool:
|
||||
if not _has_table(table_name):
|
||||
return False
|
||||
inspector = inspect(op.get_bind())
|
||||
return any(idx["name"] == index_name for idx in inspector.get_indexes(table_name))
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if _has_table(_TABLE) and not _has_column(_TABLE, _COLUMN):
|
||||
# server_default mirrors the ORM declaration so the sweep on live
|
||||
# databases and this migration produce the same NOT NULL column.
|
||||
op.add_column(
|
||||
_TABLE,
|
||||
sa.Column(_COLUMN, sa.Boolean(), nullable=False, server_default=sa.text("0")),
|
||||
)
|
||||
if _has_table(_TABLE) and not _has_index(_TABLE, _INDEX):
|
||||
op.create_index(_INDEX, _TABLE, [_COLUMN])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _has_table(_TABLE) and _has_index(_TABLE, _INDEX):
|
||||
op.drop_index(_INDEX, table_name=_TABLE)
|
||||
if _has_table(_TABLE) and _has_column(_TABLE, _COLUMN):
|
||||
op.drop_column(_TABLE, _COLUMN)
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
"""Persist private knowledge-research sessions and shared publications.
|
||||
|
||||
Revision ID: 20261022_01
|
||||
Revises: 20261014_02
|
||||
Create Date: 2026-10-22
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from deerflow.persistence.types import PortableLongText
|
||||
|
||||
revision = "20261022_01"
|
||||
down_revision = "20261014_02"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "knowledge_research_sessions"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if inspector.has_table(_TABLE):
|
||||
return
|
||||
op.create_table(
|
||||
_TABLE,
|
||||
sa.Column("id", sa.String(length=36), primary_key=True),
|
||||
sa.Column("publication_id", sa.String(length=36), nullable=False),
|
||||
sa.Column("thread_id", sa.String(length=128), nullable=False),
|
||||
sa.Column("knowledge_base_id", sa.String(length=128), nullable=False),
|
||||
sa.Column("user_id", sa.String(length=255), nullable=False),
|
||||
sa.Column("title", sa.String(length=255), nullable=False),
|
||||
sa.Column("draft_markdown", PortableLongText(), nullable=False),
|
||||
sa.Column("wiki_slug", sa.String(length=512), nullable=True),
|
||||
sa.Column("wiki_page_id", sa.String(length=128), nullable=True),
|
||||
sa.Column("wiki_folder_id", sa.String(length=128), nullable=True),
|
||||
sa.Column("saved_title", sa.String(length=255), nullable=True),
|
||||
sa.Column("saved_markdown", PortableLongText(), nullable=True),
|
||||
sa.Column("saved_hash", sa.String(length=64), nullable=True),
|
||||
sa.Column("saved_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.UniqueConstraint("publication_id", name="uq_knowledge_research_publication_id"),
|
||||
sa.UniqueConstraint("thread_id", name="uq_knowledge_research_thread_id"),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_knowledge_research_sessions_publication_id",
|
||||
_TABLE,
|
||||
["publication_id"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_knowledge_research_sessions_thread_id",
|
||||
_TABLE,
|
||||
["thread_id"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_knowledge_research_sessions_knowledge_base_id",
|
||||
_TABLE,
|
||||
["knowledge_base_id"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_knowledge_research_sessions_user_id",
|
||||
_TABLE,
|
||||
["user_id"],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if sa.inspect(op.get_bind()).has_table(_TABLE):
|
||||
op.drop_table(_TABLE)
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
"""Add the integrator-supplied type partition to task deep-link details.
|
||||
|
||||
Revision ID: 20261022_02
|
||||
Revises: 20261024_01
|
||||
Create Date: 2026-10-22
|
||||
|
||||
The same task id may now carry one snapshot per business type (the deep-link
|
||||
``?type=``), so ``sub_type`` joins the primary key. Existing rows backfill to
|
||||
``''`` — the legacy no-type partition — and callers that omit the type keep
|
||||
reading/writing exactly that partition, so behaviour is unchanged for them.
|
||||
|
||||
The key change is a portable table rebuild (create-copy-drop-rename): this
|
||||
Alembic build has no batch ``drop_primary_key`` and SQLite cannot alter a
|
||||
primary key in place, so any other route leaves a two-column key that makes
|
||||
typed upserts fail with a UNIQUE constraint violation.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
from sqlalchemy.dialects import mysql as sa_mysql
|
||||
|
||||
revision = "20261022_02"
|
||||
down_revision = "20261024_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "task_deeplink_details"
|
||||
_PK = ["detail_type", "detail_id", "sub_type"]
|
||||
_OLD_PK = ["detail_type", "detail_id"]
|
||||
|
||||
|
||||
def _has_table() -> bool:
|
||||
return _TABLE in inspect(op.get_bind()).get_table_names()
|
||||
|
||||
|
||||
def _pk_columns() -> list[str] | None:
|
||||
constraint = inspect(op.get_bind()).get_pk_constraint(_TABLE)
|
||||
return list(constraint.get("constrained_columns") or []) or None
|
||||
|
||||
|
||||
def _column_specs(with_sub_type: bool) -> list[tuple[str, sa.types.TypeEngine, bool]]:
|
||||
is_mysql = op.get_bind().dialect.name == "mysql"
|
||||
specs = [
|
||||
("detail_type", sa.String(32), False),
|
||||
("detail_id", sa.String(128), False),
|
||||
("task_name", sa.String(512), False),
|
||||
("task_content", sa_mysql.LONGTEXT() if is_mysql else sa.Text(), False),
|
||||
("overview", sa_mysql.LONGTEXT() if is_mysql else sa.Text(), False),
|
||||
("extra_json", sa.Text() if is_mysql else sa.JSON(), False),
|
||||
("version", sa.Integer(), False),
|
||||
("created_by", sa.String(64), True),
|
||||
("updated_by", sa.String(64), True),
|
||||
("created_at", sa.DateTime(), False),
|
||||
("updated_at", sa.DateTime(), False),
|
||||
]
|
||||
if with_sub_type:
|
||||
specs.append(("sub_type", sa.String(64), False))
|
||||
return specs
|
||||
|
||||
|
||||
def _rebuild_table(pk_columns: list[str], with_sub_type: bool) -> None:
|
||||
"""Recreate the table (create-copy-drop-rename) with the given primary key."""
|
||||
|
||||
bind = op.get_bind()
|
||||
rebuild = _TABLE + "__rebuild"
|
||||
if rebuild in inspect(bind).get_table_names():
|
||||
op.drop_table(rebuild)
|
||||
specs = _column_specs(with_sub_type)
|
||||
op.create_table(
|
||||
rebuild,
|
||||
*[
|
||||
sa.Column(
|
||||
name,
|
||||
type_,
|
||||
nullable=nullable,
|
||||
server_default="" if name == "sub_type" else None,
|
||||
)
|
||||
for name, type_, nullable in specs
|
||||
],
|
||||
sa.PrimaryKeyConstraint(*pk_columns),
|
||||
)
|
||||
names = [name for name, _, _ in specs]
|
||||
select_expr = ", ".join(
|
||||
f"COALESCE({name}, '')" if name == "sub_type" else name for name in names
|
||||
)
|
||||
bind.execute(
|
||||
sa.text(f"INSERT INTO {rebuild} ({', '.join(names)}) SELECT {select_expr} FROM {_TABLE}")
|
||||
)
|
||||
op.drop_table(_TABLE)
|
||||
op.rename_table(rebuild, _TABLE)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not _has_table():
|
||||
# Fresh databases get the three-column key straight from create_all.
|
||||
return
|
||||
inspector = inspect(op.get_bind())
|
||||
columns = {column["name"] for column in inspector.get_columns(_TABLE)}
|
||||
if "sub_type" in columns and _pk_columns() == _PK:
|
||||
return
|
||||
if "sub_type" not in columns:
|
||||
op.add_column(
|
||||
_TABLE,
|
||||
sa.Column("sub_type", sa.String(64), nullable=False, server_default=""),
|
||||
)
|
||||
if _pk_columns() != _PK:
|
||||
_rebuild_table(_PK, with_sub_type=True)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if not _has_table():
|
||||
return
|
||||
if _pk_columns() == _OLD_PK:
|
||||
return
|
||||
_rebuild_table(_OLD_PK, with_sub_type=False)
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
"""Admin catalog switch: ``roundtable_chains.hidden``.
|
||||
|
||||
Hidden chains vanish from every non-admin listing (我的 / 公共 / 待审核 / 选链
|
||||
弹窗) while staying fully usable — single-record reads (get_chain), configured
|
||||
business mappings and in-flight roundtables are unaffected. Only the admin
|
||||
management view (``admin_view=true``) keeps listing them.
|
||||
|
||||
The Gateway's startup ORM-column sweep also adds this column on existing
|
||||
databases (Alembic auto-upgrade is disabled there); this migration serves
|
||||
environments that run Alembic manually. Fully guarded and idempotent.
|
||||
|
||||
Revision ID: 20261023_01
|
||||
Revises: 20261022_03
|
||||
Create Date: 2026-10-23
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261023_01"
|
||||
down_revision = "20261022_03"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "roundtable_chains"
|
||||
_COLUMN = "hidden"
|
||||
_INDEX = "ix_roundtable_chains_hidden"
|
||||
|
||||
|
||||
def _has_table(table_name: str) -> bool:
|
||||
return table_name in inspect(op.get_bind()).get_table_names()
|
||||
|
||||
|
||||
def _has_column(table_name: str, column_name: str) -> bool:
|
||||
if not _has_table(table_name):
|
||||
return False
|
||||
inspector = inspect(op.get_bind())
|
||||
return any(col["name"] == column_name for col in inspector.get_columns(table_name))
|
||||
|
||||
|
||||
def _has_index(table_name: str, index_name: str) -> bool:
|
||||
if not _has_table(table_name):
|
||||
return False
|
||||
inspector = inspect(op.get_bind())
|
||||
return any(idx["name"] == index_name for idx in inspector.get_indexes(table_name))
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if _has_table(_TABLE) and not _has_column(_TABLE, _COLUMN):
|
||||
op.add_column(
|
||||
_TABLE,
|
||||
sa.Column(_COLUMN, sa.Boolean(), nullable=False, server_default=sa.text("0")),
|
||||
)
|
||||
if _has_table(_TABLE) and not _has_index(_TABLE, _INDEX):
|
||||
op.create_index(_INDEX, _TABLE, [_COLUMN])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _has_table(_TABLE) and _has_index(_TABLE, _INDEX):
|
||||
op.drop_index(_INDEX, table_name=_TABLE)
|
||||
if _has_table(_TABLE) and _has_column(_TABLE, _COLUMN):
|
||||
op.drop_column(_TABLE, _COLUMN)
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
"""Index the common deep-link list path that omits sub_type.
|
||||
|
||||
Revision ID: 20261023_02
|
||||
Revises: 20261024_02, 20261022_02
|
||||
Create Date: 2026-10-22
|
||||
|
||||
``GET /api/task-deeplink-threads`` for 3qfx/rwfx/xdfx filters only
|
||||
``task_id + go_path`` and orders by ``updated_at, thread_id``. The existing
|
||||
scope index inserts ``sub_type`` before those sort columns, so the planner
|
||||
cannot use it for newest-first listing. This extra index matches that query.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261023_02"
|
||||
down_revision = ("20261024_02", "20261022_02")
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "task_deeplink_threads"
|
||||
_INDEX = "ix_task_deeplink_threads_task_go_updated"
|
||||
_COLUMNS = ["task_id", "go_path", "updated_at", "thread_id"]
|
||||
|
||||
|
||||
def _has_table() -> bool:
|
||||
return _TABLE in inspect(op.get_bind()).get_table_names()
|
||||
|
||||
|
||||
def _indexes() -> dict[str, list[str]]:
|
||||
if not _has_table():
|
||||
return {}
|
||||
return {
|
||||
str(index["name"]): [str(column) for column in index["column_names"]]
|
||||
for index in inspect(op.get_bind()).get_indexes(_TABLE)
|
||||
if index.get("name")
|
||||
}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not _has_table():
|
||||
return
|
||||
if _indexes().get(_INDEX) != _COLUMNS:
|
||||
if _INDEX in _indexes():
|
||||
op.drop_index(_INDEX, table_name=_TABLE)
|
||||
op.create_index(_INDEX, _TABLE, _COLUMNS)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if not _has_table():
|
||||
return
|
||||
if _INDEX in _indexes():
|
||||
op.drop_index(_INDEX, table_name=_TABLE)
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
"""Repair task_deeplink_details primary keys left two-column by 20261022_02.
|
||||
|
||||
Revision ID: 20261023_03
|
||||
Revises: 20261023_02
|
||||
Create Date: 2026-10-22
|
||||
|
||||
An interim build of ``20261022_02`` added the ``sub_type`` column but could
|
||||
not rebuild the primary key (the batch API it called does not exist in this
|
||||
Alembic version, and SQLite cannot alter a key in place). Databases that ran
|
||||
that build are stamped at head yet still enforce the legacy
|
||||
``(detail_type, detail_id)`` key, so typed upserts fail with a UNIQUE
|
||||
constraint violation. This revision detects that state and performs the
|
||||
portable create-copy-drop-rename rebuild; databases with the correct
|
||||
three-column key simply no-op.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
from sqlalchemy.dialects import mysql as sa_mysql
|
||||
|
||||
revision = "20261023_03"
|
||||
down_revision = "20261023_02"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "task_deeplink_details"
|
||||
_PK = ["detail_type", "detail_id", "sub_type"]
|
||||
|
||||
|
||||
def _has_table() -> bool:
|
||||
return _TABLE in inspect(op.get_bind()).get_table_names()
|
||||
|
||||
|
||||
def _pk_columns() -> list[str] | None:
|
||||
constraint = inspect(op.get_bind()).get_pk_constraint(_TABLE)
|
||||
return list(constraint.get("constrained_columns") or []) or None
|
||||
|
||||
|
||||
def _rebuild_table() -> None:
|
||||
bind = op.get_bind()
|
||||
rebuild = _TABLE + "__rebuild"
|
||||
if rebuild in inspect(bind).get_table_names():
|
||||
op.drop_table(rebuild)
|
||||
is_mysql = bind.dialect.name == "mysql"
|
||||
specs: list[tuple[str, sa.types.TypeEngine, bool]] = [
|
||||
("detail_type", sa.String(32), False),
|
||||
("detail_id", sa.String(128), False),
|
||||
("sub_type", sa.String(64), False),
|
||||
("task_name", sa.String(512), False),
|
||||
("task_content", sa_mysql.LONGTEXT() if is_mysql else sa.Text(), False),
|
||||
("overview", sa_mysql.LONGTEXT() if is_mysql else sa.Text(), False),
|
||||
("extra_json", sa.Text() if is_mysql else sa.JSON(), False),
|
||||
("version", sa.Integer(), False),
|
||||
("created_by", sa.String(64), True),
|
||||
("updated_by", sa.String(64), True),
|
||||
("created_at", sa.DateTime(), False),
|
||||
("updated_at", sa.DateTime(), False),
|
||||
]
|
||||
op.create_table(
|
||||
rebuild,
|
||||
*[
|
||||
sa.Column(
|
||||
name,
|
||||
type_,
|
||||
nullable=nullable,
|
||||
server_default="" if name == "sub_type" else None,
|
||||
)
|
||||
for name, type_, nullable in specs
|
||||
],
|
||||
sa.PrimaryKeyConstraint(*_PK),
|
||||
)
|
||||
names = [name for name, _, _ in specs]
|
||||
select_expr = ", ".join(
|
||||
f"COALESCE({name}, '')" if name == "sub_type" else name for name in names
|
||||
)
|
||||
bind.execute(
|
||||
sa.text(f"INSERT INTO {rebuild} ({', '.join(names)}) SELECT {select_expr} FROM {_TABLE}")
|
||||
)
|
||||
op.drop_table(_TABLE)
|
||||
op.rename_table(rebuild, _TABLE)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not _has_table():
|
||||
return
|
||||
if _pk_columns() == _PK:
|
||||
return
|
||||
_rebuild_table()
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# The repaired key is what 20261022_02 intended; nothing to undo.
|
||||
return
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
"""Add the b5-1 ?type= partition column to the deep-link history index.
|
||||
|
||||
Revision ID: 20261024_01
|
||||
Revises: 20261023_01
|
||||
Create Date: 2026-10-22
|
||||
|
||||
Existing rows keep sharing one partition per (task_id, go_path): the new
|
||||
``sub_type`` column backfills to ``''`` and queries that omit ``sub_type``
|
||||
continue to return every sub-type, so 3qfx/rwfx/xdfx behaviour is unchanged.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261024_01"
|
||||
down_revision = "20261023_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "task_deeplink_threads"
|
||||
_INDEX = "ix_task_deeplink_threads_scope"
|
||||
_INDEX_COLUMNS = ["task_id", "go_path", "sub_type", "updated_at", "thread_id"]
|
||||
|
||||
|
||||
def _has_table() -> bool:
|
||||
return _TABLE in inspect(op.get_bind()).get_table_names()
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not _has_table():
|
||||
# Fresh databases get the column straight from create_all.
|
||||
return
|
||||
bind = op.get_bind()
|
||||
inspector = inspect(bind)
|
||||
if "sub_type" not in {column["name"] for column in inspector.get_columns(_TABLE)}:
|
||||
op.add_column(
|
||||
_TABLE,
|
||||
sa.Column("sub_type", sa.String(64), nullable=False, server_default=""),
|
||||
)
|
||||
indexes = {index["name"]: index["column_names"] for index in inspector.get_indexes(_TABLE)}
|
||||
if indexes.get(_INDEX) != _INDEX_COLUMNS:
|
||||
if _INDEX in indexes:
|
||||
op.drop_index(_INDEX, table_name=_TABLE)
|
||||
op.create_index(_INDEX, _TABLE, _INDEX_COLUMNS)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if not _has_table():
|
||||
return
|
||||
bind = op.get_bind()
|
||||
inspector = inspect(bind)
|
||||
columns = {column["name"] for column in inspector.get_columns(_TABLE)}
|
||||
indexes = {index["name"]: index["column_names"] for index in inspector.get_indexes(_TABLE)}
|
||||
if indexes.get(_INDEX) is not None:
|
||||
op.drop_index(_INDEX, table_name=_TABLE)
|
||||
if "sub_type" in columns:
|
||||
op.drop_column(_TABLE, "sub_type")
|
||||
op.create_index(_INDEX, _TABLE, ["task_id", "go_path", "updated_at", "thread_id"])
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
"""Store deep-link list cards without joining ``threads_meta``.
|
||||
|
||||
Revision ID: 20261024_02
|
||||
Revises: 20261024_01
|
||||
Create Date: 2026-10-22
|
||||
|
||||
The dedicated history table used to be a pointer: listing still joined the
|
||||
generic ``threads_meta`` catalogue for title / status / metadata. That join
|
||||
is what made the task workspace slow once ordinary Q&A filled the catalogue.
|
||||
This revision copies those card fields onto ``task_deeplink_threads`` itself
|
||||
and backfills existing index rows from ``threads_meta``.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
from deerflow.persistence.types import PortableJSON
|
||||
|
||||
revision = "20261024_02"
|
||||
down_revision = "20261024_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "task_deeplink_threads"
|
||||
_META_TABLE = "threads_meta"
|
||||
|
||||
|
||||
def _has_table(table_name: str) -> bool:
|
||||
return table_name in inspect(op.get_bind()).get_table_names()
|
||||
|
||||
|
||||
def _columns() -> set[str]:
|
||||
if not _has_table(_TABLE):
|
||||
return set()
|
||||
return {str(column["name"]) for column in inspect(op.get_bind()).get_columns(_TABLE)}
|
||||
|
||||
|
||||
def _backfill_cards() -> None:
|
||||
if not _has_table(_META_TABLE):
|
||||
return
|
||||
bind = op.get_bind()
|
||||
dialect = bind.dialect.name
|
||||
if dialect in {"postgresql", "opengauss"}:
|
||||
bind.execute(
|
||||
sa.text(
|
||||
f"UPDATE {_TABLE} AS t "
|
||||
"SET display_name = m.display_name, "
|
||||
"status = COALESCE(m.status, 'idle'), "
|
||||
"metadata_json = m.metadata_json "
|
||||
f"FROM {_META_TABLE} AS m "
|
||||
"WHERE m.thread_id = t.thread_id"
|
||||
)
|
||||
)
|
||||
return
|
||||
if dialect == "mysql":
|
||||
bind.execute(
|
||||
sa.text(
|
||||
f"UPDATE {_TABLE} AS t "
|
||||
f"JOIN {_META_TABLE} AS m ON m.thread_id = t.thread_id "
|
||||
"SET t.display_name = m.display_name, "
|
||||
"t.status = COALESCE(m.status, 'idle'), "
|
||||
"t.metadata_json = m.metadata_json"
|
||||
)
|
||||
)
|
||||
return
|
||||
bind.execute(
|
||||
sa.text(
|
||||
f"UPDATE {_TABLE} SET "
|
||||
"display_name = ("
|
||||
f"SELECT display_name FROM {_META_TABLE} "
|
||||
f"WHERE {_META_TABLE}.thread_id = {_TABLE}.thread_id"
|
||||
"), "
|
||||
"status = COALESCE(("
|
||||
f"SELECT status FROM {_META_TABLE} "
|
||||
f"WHERE {_META_TABLE}.thread_id = {_TABLE}.thread_id"
|
||||
"), 'idle'), "
|
||||
"metadata_json = ("
|
||||
f"SELECT metadata_json FROM {_META_TABLE} "
|
||||
f"WHERE {_META_TABLE}.thread_id = {_TABLE}.thread_id"
|
||||
")"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not _has_table(_TABLE):
|
||||
return
|
||||
columns = _columns()
|
||||
if "display_name" not in columns:
|
||||
op.add_column(_TABLE, sa.Column("display_name", sa.String(256), nullable=True))
|
||||
if "status" not in columns:
|
||||
op.add_column(
|
||||
_TABLE,
|
||||
sa.Column("status", sa.String(20), nullable=False, server_default="idle"),
|
||||
)
|
||||
if "metadata_json" not in columns:
|
||||
op.add_column(_TABLE, sa.Column("metadata_json", PortableJSON(), nullable=True))
|
||||
_backfill_cards()
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if not _has_table(_TABLE):
|
||||
return
|
||||
columns = _columns()
|
||||
if "metadata_json" in columns:
|
||||
op.drop_column(_TABLE, "metadata_json")
|
||||
if "status" in columns:
|
||||
op.drop_column(_TABLE, "status")
|
||||
if "display_name" in columns:
|
||||
op.drop_column(_TABLE, "display_name")
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
"""Indexes for the agent gallery category tabs and tag filters.
|
||||
|
||||
Revision ID: 20261025_01
|
||||
Revises: 20261023_03
|
||||
Create Date: 2026-10-23
|
||||
|
||||
The gallery "广场" tab filters ``hidden`` + ``is_private`` + ``square_id``,
|
||||
and "我的" filters ``user_id`` + ``hidden``. Tag chips join
|
||||
``tag_assignments`` by ``(target_type, target_id)`` and filter by
|
||||
``(target_type, tag_id)``. Single-column indexes and the existing unique
|
||||
key (which leads with ``tag_id``) do not cover those predicates.
|
||||
|
||||
Startup also creates missing ORM indexes, so deployments that skip Alembic
|
||||
still receive these. This revision stays idempotent for the ones that run it.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261025_01"
|
||||
down_revision = "20261023_03"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_INDEXES = (
|
||||
("agents", "ix_agents_catalog_square", ("hidden", "is_private", "square_id", "created_at")),
|
||||
("agents", "ix_agents_owner_hidden", ("user_id", "hidden", "created_at")),
|
||||
("tag_assignments", "ix_tag_assignments_type_target", ("target_type", "target_id")),
|
||||
("tag_assignments", "ix_tag_assignments_type_tag", ("target_type", "tag_id", "target_id")),
|
||||
)
|
||||
|
||||
|
||||
def _has_table(table_name: str) -> bool:
|
||||
return table_name in inspect(op.get_bind()).get_table_names()
|
||||
|
||||
|
||||
def _has_index(table_name: str, index_name: str) -> bool:
|
||||
if not _has_table(table_name):
|
||||
return False
|
||||
return any(idx["name"] == index_name for idx in inspect(op.get_bind()).get_indexes(table_name))
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
for table_name, index_name, columns in _INDEXES:
|
||||
if _has_table(table_name) and not _has_index(table_name, index_name):
|
||||
op.create_index(index_name, table_name, list(columns))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
for table_name, index_name, _columns in reversed(_INDEXES):
|
||||
if _has_table(table_name) and _has_index(table_name, index_name):
|
||||
op.drop_index(index_name, table_name=table_name)
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
"""Add shared nonce storage for scoped service-token exchange.
|
||||
|
||||
Revision ID: 20261025_02
|
||||
Revises: 20261025_01
|
||||
Create Date: 2026-10-24
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261025_02"
|
||||
down_revision = "20261025_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "auth_service_nonces"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if _TABLE in inspect(op.get_bind()).get_table_names():
|
||||
return
|
||||
op.create_table(
|
||||
_TABLE,
|
||||
sa.Column("nonce_hash", sa.String(64), primary_key=True),
|
||||
sa.Column("client_id", sa.String(128), nullable=False),
|
||||
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_index("ix_auth_service_nonces_client_id", _TABLE, ["client_id"])
|
||||
op.create_index("ix_auth_service_nonces_expires_at", _TABLE, ["expires_at"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _TABLE in inspect(op.get_bind()).get_table_names():
|
||||
op.drop_table(_TABLE)
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
"""Add the database-backed skill catalogue snapshot for list requests.
|
||||
|
||||
Revision ID: 20261025_03
|
||||
Revises: 20261025_02
|
||||
Create Date: 2026-10-25
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261025_03"
|
||||
down_revision = "20261025_02"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "skill_catalog_snapshots"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if _TABLE in inspect(op.get_bind()).get_table_names():
|
||||
return
|
||||
op.create_table(
|
||||
_TABLE,
|
||||
sa.Column("cache_key", sa.String(32), primary_key=True),
|
||||
sa.Column("catalog_json", sa.Text(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _TABLE in inspect(op.get_bind()).get_table_names():
|
||||
op.drop_table(_TABLE)
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
"""Index canonical usernames for fast SSO and username login.
|
||||
|
||||
Revision ID: 20261026_01
|
||||
Revises: 20261025_03
|
||||
Create Date: 2026-10-26
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261026_01"
|
||||
down_revision = "20261025_03"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "users"
|
||||
_COLUMN = "username_key"
|
||||
_INDEX = "ix_users_username_key_created_at"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
inspector = inspect(op.get_bind())
|
||||
if _TABLE not in inspector.get_table_names():
|
||||
return
|
||||
|
||||
columns = {column["name"] for column in inspector.get_columns(_TABLE)}
|
||||
if _COLUMN not in columns:
|
||||
op.add_column(_TABLE, sa.Column(_COLUMN, sa.String(128), nullable=True))
|
||||
|
||||
indexes = {index["name"] for index in inspect(op.get_bind()).get_indexes(_TABLE)}
|
||||
if _INDEX not in indexes:
|
||||
op.create_index(_INDEX, _TABLE, [_COLUMN, "created_at"])
|
||||
|
||||
# Backfill the normalized local part once. Login requests then use a
|
||||
# bounded indexed equality lookup instead of LOWER(email) LIKE 'name@%'.
|
||||
bind = op.get_bind()
|
||||
rows = bind.execute(sa.text("SELECT id, email FROM users")).fetchall()
|
||||
for user_id, email in rows:
|
||||
if not email or "@" not in email:
|
||||
continue
|
||||
username_key = str(email).split("@", 1)[0].strip().lower()[:128]
|
||||
bind.execute(
|
||||
sa.text(
|
||||
"UPDATE users SET username_key = :username_key "
|
||||
"WHERE id = :user_id AND (username_key IS NULL OR username_key = '')"
|
||||
),
|
||||
{"username_key": username_key, "user_id": user_id},
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _TABLE not in inspect(op.get_bind()).get_table_names():
|
||||
return
|
||||
indexes = {index["name"] for index in inspect(op.get_bind()).get_indexes(_TABLE)}
|
||||
if _INDEX in indexes:
|
||||
op.drop_index(_INDEX, table_name=_TABLE)
|
||||
columns = {column["name"] for column in inspect(op.get_bind()).get_columns(_TABLE)}
|
||||
if _COLUMN in columns:
|
||||
op.drop_column(_TABLE, _COLUMN)
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
"""Persist the globally shared default reasoning effort for each model.
|
||||
|
||||
Revision ID: 20261026_02
|
||||
Revises: 20261026_01, 20261022_01
|
||||
Create Date: 2026-10-26
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261026_02"
|
||||
down_revision = ("20261026_01", "20261022_01")
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "model_capabilities"
|
||||
_COLUMN = "default_reasoning_effort"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
inspector = inspect(op.get_bind())
|
||||
if _TABLE not in inspector.get_table_names():
|
||||
return
|
||||
if _COLUMN not in {column["name"] for column in inspector.get_columns(_TABLE)}:
|
||||
op.add_column(
|
||||
_TABLE,
|
||||
sa.Column(
|
||||
_COLUMN,
|
||||
sa.String(length=16),
|
||||
nullable=False,
|
||||
server_default="xhigh",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
inspector = inspect(op.get_bind())
|
||||
if _TABLE not in inspector.get_table_names():
|
||||
return
|
||||
if _COLUMN in {column["name"] for column in inspector.get_columns(_TABLE)}:
|
||||
op.drop_column(_TABLE, _COLUMN)
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
"""Persist the administrator-configured Redis cache TTL.
|
||||
|
||||
Revision ID: 20261029_01
|
||||
Revises: 20261026_02
|
||||
Create Date: 2026-10-29
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261029_01"
|
||||
down_revision = "20261026_02"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "api_read_cache_settings"
|
||||
_COLUMN = "ttl_seconds"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
inspector = inspect(op.get_bind())
|
||||
if _TABLE not in inspector.get_table_names():
|
||||
return
|
||||
if _COLUMN not in {column["name"] for column in inspector.get_columns(_TABLE)}:
|
||||
op.add_column(
|
||||
_TABLE,
|
||||
sa.Column(
|
||||
_COLUMN,
|
||||
sa.Integer(),
|
||||
nullable=False,
|
||||
server_default=sa.text("300"),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
inspector = inspect(op.get_bind())
|
||||
if _TABLE not in inspector.get_table_names():
|
||||
return
|
||||
if _COLUMN in {column["name"] for column in inspector.get_columns(_TABLE)}:
|
||||
op.drop_column(_TABLE, _COLUMN)
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"""Persist per-API cache switches and browser status access control."""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "20261029_02"
|
||||
down_revision = "20261029_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if "api_read_cache_settings" not in inspector.get_table_names():
|
||||
return
|
||||
columns = {column["name"] for column in inspector.get_columns("api_read_cache_settings")}
|
||||
if "collection_overrides" not in columns:
|
||||
op.add_column("api_read_cache_settings", sa.Column("collection_overrides", sa.JSON(), nullable=True))
|
||||
if "browser_status_enabled" not in columns:
|
||||
op.add_column("api_read_cache_settings", sa.Column("browser_status_enabled", sa.Boolean(), nullable=False, server_default=sa.true()))
|
||||
if "cache_epoch" not in columns:
|
||||
op.add_column("api_read_cache_settings", sa.Column("cache_epoch", sa.String(32), nullable=False, server_default="0"))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if "api_read_cache_settings" not in inspector.get_table_names():
|
||||
return
|
||||
columns = {column["name"] for column in inspector.get_columns("api_read_cache_settings")}
|
||||
for name in ("cache_epoch", "browser_status_enabled", "collection_overrides"):
|
||||
if name in columns:
|
||||
op.drop_column("api_read_cache_settings", name)
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
"""Add per-item enablement to compact menu overrides.
|
||||
|
||||
Existing compact-menu items remain enabled. New databases receive the field
|
||||
from ``CompactMenuOverrideRow``; this revision and the startup ORM schema sweep
|
||||
add it safely to deployments with an existing ``compact_menu_overrides`` table.
|
||||
|
||||
Revision ID: 20261102_01
|
||||
Revises: 20261029_02
|
||||
Create Date: 2026-11-02
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261102_01"
|
||||
down_revision = "20261029_02"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "compact_menu_overrides"
|
||||
_COLUMN = "disabled"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
inspector = inspect(op.get_bind())
|
||||
if _TABLE not in inspector.get_table_names():
|
||||
return
|
||||
if _COLUMN not in {column["name"] for column in inspector.get_columns(_TABLE)}:
|
||||
op.add_column(
|
||||
_TABLE,
|
||||
sa.Column(_COLUMN, sa.Boolean(), nullable=False, server_default=sa.false()),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
inspector = inspect(op.get_bind())
|
||||
if _TABLE not in inspector.get_table_names():
|
||||
return
|
||||
if _COLUMN in {column["name"] for column in inspector.get_columns(_TABLE)}:
|
||||
op.drop_column(_TABLE, _COLUMN)
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
"""Allow administrator-defined business-mapping types and login goPaths.
|
||||
|
||||
Revision ID: 20261102_02
|
||||
Revises: 20261102_01
|
||||
Create Date: 2026-11-02
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
revision = "20261102_02"
|
||||
down_revision = "20261102_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_MAPPING_TABLE = "business_mapping"
|
||||
_THREAD_TABLE = "task_deeplink_threads"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
inspector = inspect(op.get_bind())
|
||||
tables = set(inspector.get_table_names())
|
||||
if _MAPPING_TABLE in tables:
|
||||
columns = {column["name"] for column in inspector.get_columns(_MAPPING_TABLE)}
|
||||
if "mapping_type" not in columns:
|
||||
op.add_column(
|
||||
_MAPPING_TABLE,
|
||||
sa.Column("mapping_type", sa.String(64), nullable=False, server_default="内置业务"),
|
||||
)
|
||||
if "is_custom" not in columns:
|
||||
op.add_column(
|
||||
_MAPPING_TABLE,
|
||||
sa.Column("is_custom", sa.Boolean(), nullable=False, server_default=sa.false()),
|
||||
)
|
||||
|
||||
# PostgreSQL enforces VARCHAR length, unlike SQLite. Widen the dedicated
|
||||
# history partition too so a 32-character custom goPath can be persisted.
|
||||
if _THREAD_TABLE in tables:
|
||||
with op.batch_alter_table(_THREAD_TABLE) as batch:
|
||||
batch.alter_column(
|
||||
"go_path",
|
||||
existing_type=sa.String(16),
|
||||
type_=sa.String(32),
|
||||
existing_nullable=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
inspector = inspect(op.get_bind())
|
||||
tables = set(inspector.get_table_names())
|
||||
if _THREAD_TABLE in tables:
|
||||
with op.batch_alter_table(_THREAD_TABLE) as batch:
|
||||
batch.alter_column(
|
||||
"go_path",
|
||||
existing_type=sa.String(32),
|
||||
type_=sa.String(16),
|
||||
existing_nullable=False,
|
||||
)
|
||||
if _MAPPING_TABLE in tables:
|
||||
columns = {column["name"] for column in inspector.get_columns(_MAPPING_TABLE)}
|
||||
if "is_custom" in columns:
|
||||
op.drop_column(_MAPPING_TABLE, "is_custom")
|
||||
if "mapping_type" in columns:
|
||||
op.drop_column(_MAPPING_TABLE, "mapping_type")
|
||||
Reference in new issue
Block a user