feat: 新增岗位管理、提示词模板与资源标签,完善用户提示词与推荐问题接口
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2f414c6e08
commit
3855c30edd
52 files changed
+3143
-57
No files matched your search
+108
@@ -0,0 +1,108 @@
|
||||
"""岗位 (position) subscription system.
|
||||
|
||||
New tables ``positions`` + ``position_tag_bindings``; new column
|
||||
``users.position_id``; ``origin`` / ``position_id`` on ``agent_favorites`` and
|
||||
``scheduled_task_subscriptions``; ``is_template`` / ``origin`` / ``template_id``
|
||||
/ ``position_id`` on ``user_custom_prompts``.
|
||||
|
||||
Note: the running app also auto-adds these via ``_ensure_orm_columns_sync`` and
|
||||
``create_all`` on startup; this migration keeps the alembic history consistent
|
||||
per the repo convention (see backend/CLAUDE.md → Schema Migrations).
|
||||
|
||||
Revision ID: 20260616_01
|
||||
Revises: 20260612_01
|
||||
Create Date: 2026-06-16
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
|
||||
revision = "20260616_01"
|
||||
down_revision = "20260612_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
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
|
||||
return any(col["name"] == column_name for col in inspect(op.get_bind()).get_columns(table_name))
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not _has_table("positions"):
|
||||
op.create_table(
|
||||
"positions",
|
||||
sa.Column("id", sa.String(64), primary_key=True),
|
||||
sa.Column("name", sa.String(191), nullable=False),
|
||||
sa.Column("description", sa.String(1024), nullable=False, server_default=""),
|
||||
sa.Column("is_default", sa.Boolean(), nullable=False, server_default=sa.text("0")),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.UniqueConstraint("name", name="uq_positions_name"),
|
||||
)
|
||||
op.create_index("ix_positions_is_default", "positions", ["is_default"])
|
||||
|
||||
if not _has_table("position_tag_bindings"):
|
||||
op.create_table(
|
||||
"position_tag_bindings",
|
||||
sa.Column("id", sa.String(64), primary_key=True),
|
||||
sa.Column("position_id", sa.String(64), nullable=False),
|
||||
sa.Column("resource_type", sa.String(32), nullable=False),
|
||||
sa.Column("tag_id", sa.String(64), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.UniqueConstraint("position_id", "resource_type", "tag_id", name="uq_position_tag_bindings"),
|
||||
)
|
||||
op.create_index("ix_position_tag_bindings_position_id", "position_tag_bindings", ["position_id"])
|
||||
op.create_index("ix_position_tag_bindings_resource_type", "position_tag_bindings", ["resource_type"])
|
||||
op.create_index("ix_position_tag_bindings_tag_id", "position_tag_bindings", ["tag_id"])
|
||||
op.create_index("ix_position_tag_bindings_position_type", "position_tag_bindings", ["position_id", "resource_type"])
|
||||
|
||||
if _has_table("users") and not _has_column("users", "position_id"):
|
||||
op.add_column("users", sa.Column("position_id", sa.String(64), nullable=True))
|
||||
op.create_index("ix_users_position_id", "users", ["position_id"])
|
||||
|
||||
for table in ("agent_favorites", "scheduled_task_subscriptions"):
|
||||
if _has_table(table) and not _has_column(table, "origin"):
|
||||
op.add_column(table, sa.Column("origin", sa.String(16), nullable=False, server_default="user"))
|
||||
if _has_table(table) and not _has_column(table, "position_id"):
|
||||
op.add_column(table, sa.Column("position_id", sa.String(64), nullable=True))
|
||||
op.create_index(f"ix_{table}_position_id", table, ["position_id"])
|
||||
|
||||
if _has_table("user_custom_prompts"):
|
||||
if not _has_column("user_custom_prompts", "is_template"):
|
||||
op.add_column("user_custom_prompts", sa.Column("is_template", sa.Boolean(), nullable=False, server_default=sa.text("0")))
|
||||
op.create_index("ix_user_custom_prompts_is_template", "user_custom_prompts", ["is_template"])
|
||||
if not _has_column("user_custom_prompts", "origin"):
|
||||
op.add_column("user_custom_prompts", sa.Column("origin", sa.String(16), nullable=False, server_default="user"))
|
||||
if not _has_column("user_custom_prompts", "template_id"):
|
||||
op.add_column("user_custom_prompts", sa.Column("template_id", sa.String(64), nullable=True))
|
||||
op.create_index("ix_user_custom_prompts_template_id", "user_custom_prompts", ["template_id"])
|
||||
if not _has_column("user_custom_prompts", "position_id"):
|
||||
op.add_column("user_custom_prompts", sa.Column("position_id", sa.String(64), nullable=True))
|
||||
op.create_index("ix_user_custom_prompts_position_id", "user_custom_prompts", ["position_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
for table in ("agent_favorites", "scheduled_task_subscriptions"):
|
||||
if _has_column(table, "position_id"):
|
||||
op.drop_column(table, "position_id")
|
||||
if _has_column(table, "origin"):
|
||||
op.drop_column(table, "origin")
|
||||
for col in ("position_id", "template_id", "origin", "is_template"):
|
||||
if _has_column("user_custom_prompts", col):
|
||||
op.drop_column("user_custom_prompts", col)
|
||||
if _has_column("users", "position_id"):
|
||||
op.drop_column("users", "position_id")
|
||||
if _has_table("position_tag_bindings"):
|
||||
op.drop_table("position_tag_bindings")
|
||||
if _has_table("positions"):
|
||||
op.drop_table("positions")
|
||||
Reference in new issue
Block a user