增加代码知识库;修复文档处理内容;增加API设置
This commit is contained in:
@@ -12,7 +12,16 @@ from app.models.base import Base
|
||||
from app.models.user import User
|
||||
from app.models.knowledge import KnowledgeBase, Document
|
||||
from app.models.chat import Chat, Message
|
||||
from app.models.tooling import ToolJob, SRSExtraction, SRSRequirement
|
||||
from app.models.model_config import UserModelConfig
|
||||
from app.models.tooling import (
|
||||
CodeKnowledgeBase,
|
||||
ConsistencyJob,
|
||||
ConsistencyResult,
|
||||
SRSExtraction,
|
||||
SRSRequirement,
|
||||
TestingGeneration,
|
||||
ToolJob,
|
||||
)
|
||||
from app.core.config import settings
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
@@ -87,4 +96,4 @@ def run_migrations_online() -> None:
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
run_migrations_online()
|
||||
|
||||
@@ -18,42 +18,51 @@ branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def _ensure_index(table_name: str, index_name: str, columns: list[str]) -> None:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
existing_indexes = {item["name"] for item in inspector.get_indexes(table_name)}
|
||||
if index_name not in existing_indexes:
|
||||
op.create_index(index_name, table_name, columns, unique=False)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"testing_generations",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("job_id", sa.Integer(), nullable=False),
|
||||
sa.Column("source_job_id", sa.Integer(), nullable=True),
|
||||
sa.Column("source_document_name", sa.String(length=255), nullable=False),
|
||||
sa.Column("generated_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("total_requirements", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("knowledge_base_id", sa.Integer(), nullable=True),
|
||||
sa.Column("generated_file", sa.JSON(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["job_id"], ["tool_jobs.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["knowledge_base_id"], ["knowledge_bases.id"]),
|
||||
sa.ForeignKeyConstraint(["source_job_id"], ["tool_jobs.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("job_id"),
|
||||
)
|
||||
op.create_index(op.f("ix_testing_generations_id"), "testing_generations", ["id"], unique=False)
|
||||
op.create_index(
|
||||
op.f("ix_testing_generations_source_job_id"),
|
||||
"testing_generations",
|
||||
["source_job_id"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_testing_generations_knowledge_base_id"),
|
||||
"testing_generations",
|
||||
["knowledge_base_id"],
|
||||
unique=False,
|
||||
)
|
||||
table_name = "testing_generations"
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if table_name not in inspector.get_table_names():
|
||||
op.create_table(
|
||||
table_name,
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("job_id", sa.Integer(), nullable=False),
|
||||
sa.Column("source_job_id", sa.Integer(), nullable=True),
|
||||
sa.Column("source_document_name", sa.String(length=255), nullable=False),
|
||||
sa.Column("generated_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("total_requirements", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("knowledge_base_id", sa.Integer(), nullable=True),
|
||||
sa.Column("generated_file", sa.JSON(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["job_id"], ["tool_jobs.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["knowledge_base_id"], ["knowledge_bases.id"]),
|
||||
sa.ForeignKeyConstraint(["source_job_id"], ["tool_jobs.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("job_id"),
|
||||
)
|
||||
_ensure_index(table_name, op.f("ix_testing_generations_id"), ["id"])
|
||||
_ensure_index(table_name, op.f("ix_testing_generations_source_job_id"), ["source_job_id"])
|
||||
_ensure_index(table_name, op.f("ix_testing_generations_knowledge_base_id"), ["knowledge_base_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(op.f("ix_testing_generations_knowledge_base_id"), table_name="testing_generations")
|
||||
op.drop_index(op.f("ix_testing_generations_source_job_id"), table_name="testing_generations")
|
||||
op.drop_index(op.f("ix_testing_generations_id"), table_name="testing_generations")
|
||||
op.drop_table("testing_generations")
|
||||
table_name = "testing_generations"
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if table_name not in inspector.get_table_names():
|
||||
return
|
||||
existing_indexes = {item["name"] for item in inspector.get_indexes(table_name)}
|
||||
for index_name in [
|
||||
op.f("ix_testing_generations_knowledge_base_id"),
|
||||
op.f("ix_testing_generations_source_job_id"),
|
||||
op.f("ix_testing_generations_id"),
|
||||
]:
|
||||
if index_name in existing_indexes:
|
||||
op.drop_index(index_name, table_name=table_name)
|
||||
op.drop_table(table_name)
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
"""add consistency comparison tables
|
||||
|
||||
Revision ID: d4c2a9e8b731
|
||||
Revises: c9f6e7a1bd34
|
||||
Create Date: 2026-05-10 00:00:00.000000
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision: str = "d4c2a9e8b731"
|
||||
down_revision: Union[str, None] = "c9f6e7a1bd34"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"code_knowledge_bases",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sa.String(length=255), nullable=False),
|
||||
sa.Column("project_path", sa.String(length=1024), nullable=True),
|
||||
sa.Column("vector_path", sa.String(length=1024), nullable=False),
|
||||
sa.Column("metadata_path", sa.String(length=1024), nullable=False),
|
||||
sa.Column("graph_path", sa.String(length=1024), nullable=False),
|
||||
sa.Column("status", sa.String(length=32), nullable=False),
|
||||
sa.Column("metadata_summary", sa.JSON(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(op.f("ix_code_knowledge_bases_id"), "code_knowledge_bases", ["id"], unique=False)
|
||||
op.create_index(op.f("ix_code_knowledge_bases_status"), "code_knowledge_bases", ["status"], unique=False)
|
||||
op.create_index(op.f("ix_code_knowledge_bases_user_id"), "code_knowledge_bases", ["user_id"], unique=False)
|
||||
|
||||
op.create_table(
|
||||
"consistency_jobs",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||
sa.Column("srs_extraction_id", sa.Integer(), nullable=False),
|
||||
sa.Column("code_kb_id", sa.Integer(), nullable=False),
|
||||
sa.Column("status", sa.String(length=32), nullable=False),
|
||||
sa.Column("total_requirements", sa.Integer(), nullable=False),
|
||||
sa.Column("completed_requirements", sa.Integer(), nullable=False),
|
||||
sa.Column("output_summary", sa.JSON(), nullable=True),
|
||||
sa.Column("error_message", sa.Text(), nullable=True),
|
||||
sa.Column("started_at", sa.DateTime(), nullable=True),
|
||||
sa.Column("completed_at", sa.DateTime(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["code_kb_id"], ["code_knowledge_bases.id"]),
|
||||
sa.ForeignKeyConstraint(["srs_extraction_id"], ["srs_extractions.id"]),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(op.f("ix_consistency_jobs_code_kb_id"), "consistency_jobs", ["code_kb_id"], unique=False)
|
||||
op.create_index(op.f("ix_consistency_jobs_id"), "consistency_jobs", ["id"], unique=False)
|
||||
op.create_index(op.f("ix_consistency_jobs_srs_extraction_id"), "consistency_jobs", ["srs_extraction_id"], unique=False)
|
||||
op.create_index(op.f("ix_consistency_jobs_status"), "consistency_jobs", ["status"], unique=False)
|
||||
op.create_index(op.f("ix_consistency_jobs_user_id"), "consistency_jobs", ["user_id"], unique=False)
|
||||
|
||||
op.create_table(
|
||||
"consistency_results",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("job_id", sa.Integer(), nullable=False),
|
||||
sa.Column("requirement_uid", sa.String(length=64), nullable=False),
|
||||
sa.Column("verdict", sa.String(length=32), nullable=False),
|
||||
sa.Column("coverage_score", sa.Float(), nullable=False),
|
||||
sa.Column("confidence", sa.Float(), nullable=False),
|
||||
sa.Column("matched_functions", sa.JSON(), nullable=False),
|
||||
sa.Column("covered_points", sa.JSON(), nullable=False),
|
||||
sa.Column("missing_points", sa.JSON(), nullable=False),
|
||||
sa.Column("conflict_points", sa.JSON(), nullable=False),
|
||||
sa.Column("call_chain_evidence", sa.JSON(), nullable=False),
|
||||
sa.Column("suggestion", sa.Text(), nullable=True),
|
||||
sa.Column("raw_judgment", sa.JSON(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["job_id"], ["consistency_jobs.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(op.f("ix_consistency_results_id"), "consistency_results", ["id"], unique=False)
|
||||
op.create_index(op.f("ix_consistency_results_job_id"), "consistency_results", ["job_id"], unique=False)
|
||||
op.create_index(op.f("ix_consistency_results_requirement_uid"), "consistency_results", ["requirement_uid"], unique=False)
|
||||
op.create_index(op.f("ix_consistency_results_verdict"), "consistency_results", ["verdict"], unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(op.f("ix_consistency_results_verdict"), table_name="consistency_results")
|
||||
op.drop_index(op.f("ix_consistency_results_requirement_uid"), table_name="consistency_results")
|
||||
op.drop_index(op.f("ix_consistency_results_job_id"), table_name="consistency_results")
|
||||
op.drop_index(op.f("ix_consistency_results_id"), table_name="consistency_results")
|
||||
op.drop_table("consistency_results")
|
||||
|
||||
op.drop_index(op.f("ix_consistency_jobs_user_id"), table_name="consistency_jobs")
|
||||
op.drop_index(op.f("ix_consistency_jobs_status"), table_name="consistency_jobs")
|
||||
op.drop_index(op.f("ix_consistency_jobs_srs_extraction_id"), table_name="consistency_jobs")
|
||||
op.drop_index(op.f("ix_consistency_jobs_id"), table_name="consistency_jobs")
|
||||
op.drop_index(op.f("ix_consistency_jobs_code_kb_id"), table_name="consistency_jobs")
|
||||
op.drop_table("consistency_jobs")
|
||||
|
||||
op.drop_index(op.f("ix_code_knowledge_bases_user_id"), table_name="code_knowledge_bases")
|
||||
op.drop_index(op.f("ix_code_knowledge_bases_status"), table_name="code_knowledge_bases")
|
||||
op.drop_index(op.f("ix_code_knowledge_bases_id"), table_name="code_knowledge_bases")
|
||||
op.drop_table("code_knowledge_bases")
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
"""add user model configs
|
||||
|
||||
Revision ID: e9b1b3d7a4c9
|
||||
Revises: d4c2a9e8b731
|
||||
Create Date: 2026-05-16 00:00:00.000000
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision: str = "e9b1b3d7a4c9"
|
||||
down_revision: Union[str, None] = "d4c2a9e8b731"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
table_name = "user_model_configs"
|
||||
|
||||
if table_name not in inspector.get_table_names():
|
||||
op.create_table(
|
||||
table_name,
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sa.String(length=255), nullable=False),
|
||||
sa.Column("provider", sa.String(length=64), nullable=False),
|
||||
sa.Column("api_key", sa.Text(), nullable=False),
|
||||
sa.Column("api_base", sa.String(length=512), nullable=True),
|
||||
sa.Column("chat_model", sa.String(length=128), nullable=False),
|
||||
sa.Column("embedding_model", sa.String(length=128), nullable=False),
|
||||
sa.Column("is_active", sa.Boolean(), nullable=False),
|
||||
sa.Column("last_used_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
|
||||
existing_indexes = {item["name"] for item in inspector.get_indexes(table_name)}
|
||||
for index_name, columns in {
|
||||
op.f("ix_user_model_configs_id"): ["id"],
|
||||
op.f("ix_user_model_configs_is_active"): ["is_active"],
|
||||
op.f("ix_user_model_configs_user_id"): ["user_id"],
|
||||
}.items():
|
||||
if index_name not in existing_indexes:
|
||||
op.create_index(index_name, table_name, columns, unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
table_name = "user_model_configs"
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if table_name not in inspector.get_table_names():
|
||||
return
|
||||
existing_indexes = {item["name"] for item in inspector.get_indexes(table_name)}
|
||||
for index_name in [
|
||||
op.f("ix_user_model_configs_user_id"),
|
||||
op.f("ix_user_model_configs_is_active"),
|
||||
op.f("ix_user_model_configs_id"),
|
||||
]:
|
||||
if index_name in existing_indexes:
|
||||
op.drop_index(index_name, table_name=table_name)
|
||||
op.drop_table(table_name)
|
||||
@@ -0,0 +1,57 @@
|
||||
"""repair testing generations table
|
||||
|
||||
Revision ID: f0a1b2c3d4e5
|
||||
Revises: e9b1b3d7a4c9
|
||||
Create Date: 2026-05-16 10:05:00.000000
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision: str = "f0a1b2c3d4e5"
|
||||
down_revision: Union[str, None] = "e9b1b3d7a4c9"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def _ensure_index(table_name: str, index_name: str, columns: list[str]) -> None:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
existing_indexes = {item["name"] for item in inspector.get_indexes(table_name)}
|
||||
if index_name not in existing_indexes:
|
||||
op.create_index(index_name, table_name, columns, unique=False)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
table_name = "testing_generations"
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if table_name not in inspector.get_table_names():
|
||||
op.create_table(
|
||||
table_name,
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("job_id", sa.Integer(), nullable=False),
|
||||
sa.Column("source_job_id", sa.Integer(), nullable=True),
|
||||
sa.Column("source_document_name", sa.String(length=255), nullable=False),
|
||||
sa.Column("generated_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("total_requirements", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("knowledge_base_id", sa.Integer(), nullable=True),
|
||||
sa.Column("generated_file", sa.JSON(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["job_id"], ["tool_jobs.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["knowledge_base_id"], ["knowledge_bases.id"]),
|
||||
sa.ForeignKeyConstraint(["source_job_id"], ["tool_jobs.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("job_id"),
|
||||
)
|
||||
|
||||
_ensure_index(table_name, op.f("ix_testing_generations_id"), ["id"])
|
||||
_ensure_index(table_name, op.f("ix_testing_generations_source_job_id"), ["source_job_id"])
|
||||
_ensure_index(table_name, op.f("ix_testing_generations_knowledge_base_id"), ["knowledge_base_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Repair migration: keep existing data and schema intact on downgrade.
|
||||
pass
|
||||
Reference in New Issue
Block a user