feat(db): F3a prompt_templates 表 + 迁移
新增 PromptTemplate 模型(UuidPk+CreatedAt+Base;owner_id stub、title、body、 category、tool_key)+ alembic 迁移。alembic check 无漂移;ruff/mypy packages/db 干净。
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""prompt_templates table
|
||||
|
||||
Revision ID: 59a9198d4604
|
||||
Revises: d3e4f5a6b7c8
|
||||
Create Date: 2026-06-23 20:10:37.869872
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "59a9198d4604"
|
||||
down_revision: str | None = "d3e4f5a6b7c8"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table(
|
||||
"prompt_templates",
|
||||
sa.Column("owner_id", sa.Uuid(), nullable=False),
|
||||
sa.Column("title", sa.Text(), nullable=False),
|
||||
sa.Column("body", sa.Text(), nullable=False),
|
||||
sa.Column("category", sa.Text(), nullable=True),
|
||||
sa.Column("tool_key", sa.Text(), nullable=True),
|
||||
sa.Column("id", sa.Uuid(), server_default=sa.text("gen_random_uuid()"), nullable=False),
|
||||
sa.Column(
|
||||
"created_at",
|
||||
sa.DateTime(timezone=True),
|
||||
server_default=sa.text("now()"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["owner_id"],
|
||||
["users.id"],
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_prompt_templates_owner_id"), "prompt_templates", ["owner_id"], unique=False
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f("ix_prompt_templates_owner_id"), table_name="prompt_templates")
|
||||
op.drop_table("prompt_templates")
|
||||
# ### end Alembic commands ###
|
||||
@@ -284,6 +284,20 @@ class Skill(UuidPk, CreatedAt, Base):
|
||||
examples: Mapped[list[Any]] = mapped_column(JSONB, server_default=text("'[]'"))
|
||||
|
||||
|
||||
class PromptTemplate(UuidPk, CreatedAt, Base):
|
||||
"""作者保存/复用的提示词模板(单用户本地版;无分享/市场)。
|
||||
|
||||
owner_id 为单用户原型 stub;tool_key 可选关联某生成器(NULL=通用)。
|
||||
"""
|
||||
|
||||
__tablename__ = "prompt_templates"
|
||||
owner_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("users.id"), nullable=False, index=True)
|
||||
title: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
body: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
category: Mapped[str | None] = mapped_column(Text)
|
||||
tool_key: Mapped[str | None] = mapped_column(Text)
|
||||
|
||||
|
||||
class Job(UuidPk, TimestampedMixin, Base):
|
||||
__tablename__ = "jobs"
|
||||
__table_args__ = (
|
||||
|
||||
Reference in New Issue
Block a user