Release/v0.2.2 (#260)
* [modify] migration script * [add] migration script * fix(web): change form message * fix(web): the memoryContent field is compatible with numbers and strings * feat(web): code node hidden * fix(model): 1. create a basic model to check if the name and provider are duplicated. 2. The result shows error models because the provider created API Keys for all matching models. --------- Co-authored-by: Mark <zhuwenhui5566@163.com> Co-authored-by: zhaoying <yzhao96@best-inc.com> Co-authored-by: yingzhao <zhaoyingyz@126.com> Co-authored-by: Timebomb2018 <18868801967@163.com>
This commit is contained in:
@@ -630,6 +630,13 @@ class ModelBaseRepository:
|
||||
db.add(model_base)
|
||||
return model_base
|
||||
|
||||
@staticmethod
|
||||
def get_by_name_and_provider(db: Session, name: str, provider: str) -> Optional['ModelBase']:
|
||||
return db.query(ModelBase).filter(
|
||||
ModelBase.name == name,
|
||||
ModelBase.provider == provider
|
||||
).first()
|
||||
|
||||
@staticmethod
|
||||
def update(db: Session, model_base_id: uuid.UUID, data: dict) -> Optional['ModelBase']:
|
||||
model_base = db.query(ModelBase).filter(ModelBase.id == model_base_id).first()
|
||||
|
||||
@@ -508,10 +508,7 @@ class ModelApiKeyService:
|
||||
)
|
||||
if not validation_result["valid"]:
|
||||
# 记录验证失败的模型,但不抛出异常
|
||||
failed_models.append({
|
||||
"model_name": model_name,
|
||||
"error": validation_result["error"]
|
||||
})
|
||||
failed_models.append(model_name)
|
||||
continue
|
||||
|
||||
# 创建API Key
|
||||
@@ -692,6 +689,9 @@ class ModelBaseService:
|
||||
|
||||
@staticmethod
|
||||
def create_model_base(db: Session, data: model_schema.ModelBaseCreate):
|
||||
existing = ModelBaseRepository.get_by_name_and_provider(db, data.name, data.provider)
|
||||
if existing:
|
||||
raise BusinessException("模型已存在", BizCode.DUPLICATE_NAME)
|
||||
model_base = ModelBaseRepository.create(db, data.model_dump())
|
||||
db.commit()
|
||||
db.refresh(model_base)
|
||||
|
||||
@@ -28,7 +28,15 @@ def upgrade() -> None:
|
||||
op.drop_constraint('data_config_pkey', 'memory_config', type_='primary')
|
||||
op.alter_column('memory_config', 'config_id', new_column_name='config_id_old', nullable=True)
|
||||
op.add_column('memory_config', sa.Column('config_id', sa.UUID(), nullable=True))
|
||||
op.execute("UPDATE memory_config SET config_id = apply_id::uuid")
|
||||
# Handle rows where apply_id might be NULL or invalid - generate new UUIDs for those
|
||||
op.execute("""
|
||||
UPDATE memory_config
|
||||
SET config_id = CASE
|
||||
WHEN apply_id IS NOT NULL AND apply_id ~ '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
|
||||
THEN apply_id::uuid
|
||||
ELSE gen_random_uuid()
|
||||
END
|
||||
""")
|
||||
op.alter_column('memory_config', 'config_id', nullable=False)
|
||||
op.create_primary_key('memory_config_pkey', 'memory_config', ['config_id'])
|
||||
op.execute("ALTER TABLE memory_config ALTER COLUMN config_id_old DROP DEFAULT")
|
||||
|
||||
80
api/migrations/versions/5de9b1e28509_20260129212722.py
Normal file
80
api/migrations/versions/5de9b1e28509_20260129212722.py
Normal file
@@ -0,0 +1,80 @@
|
||||
"""20260129212722
|
||||
|
||||
Revision ID: 5de9b1e28509
|
||||
Revises: 5ca246ee7dd4
|
||||
Create Date: 2026-01-29 21:34:30.978031
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '5de9b1e28509'
|
||||
down_revision: Union[str, None] = '5ca246ee7dd4'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Neo4j migration: rename group_id to end_user_id
|
||||
import asyncio
|
||||
|
||||
from app.repositories.neo4j.neo4j_connector import Neo4jConnector
|
||||
|
||||
async def run_neo4j_upgrade():
|
||||
connector = Neo4jConnector()
|
||||
try:
|
||||
async def transaction_func(tx):
|
||||
result = await tx.run("""
|
||||
MATCH (n)
|
||||
WHERE n.group_id IS NOT NULL
|
||||
SET n.end_user_id = n.group_id
|
||||
REMOVE n.group_id
|
||||
WITH count(n) AS node_count
|
||||
MATCH ()-[r]->()
|
||||
WHERE r.group_id IS NOT NULL
|
||||
SET r.end_user_id = r.group_id
|
||||
REMOVE r.group_id
|
||||
RETURN node_count, count(r) AS rel_count
|
||||
""")
|
||||
return await result.data()
|
||||
|
||||
await connector.execute_write_transaction(transaction_func)
|
||||
finally:
|
||||
await connector.close()
|
||||
|
||||
asyncio.run(run_neo4j_upgrade())
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Neo4j migration: rename end_user_id back to group_id
|
||||
import asyncio
|
||||
|
||||
from app.repositories.neo4j.neo4j_connector import Neo4jConnector
|
||||
|
||||
async def run_neo4j_downgrade():
|
||||
connector = Neo4jConnector()
|
||||
try:
|
||||
async def transaction_func(tx):
|
||||
result = await tx.run("""
|
||||
MATCH (n)
|
||||
WHERE n.end_user_id IS NOT NULL
|
||||
SET n.group_id = n.end_user_id
|
||||
REMOVE n.end_user_id
|
||||
WITH count(n) AS node_count
|
||||
MATCH ()-[r]->()
|
||||
WHERE r.end_user_id IS NOT NULL
|
||||
SET r.group_id = r.end_user_id
|
||||
REMOVE r.end_user_id
|
||||
RETURN node_count, count(r) AS rel_count
|
||||
""")
|
||||
return await result.data()
|
||||
|
||||
await connector.execute_write_transaction(transaction_func)
|
||||
finally:
|
||||
await connector.close()
|
||||
|
||||
asyncio.run(run_neo4j_downgrade())
|
||||
Reference in New Issue
Block a user