feat(chat): save and view chat history — admin-only saved_chats, History page, open-a-chat return
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
"""saved_chats: owner-saved chat conversations
|
||||
|
||||
Revision ID: 0008
|
||||
Revises: 0007
|
||||
Create Date: 2026-08-29
|
||||
|
||||
Phase 50 (save-and-view-chat-history story, A13 — one additive,
|
||||
reversible table, no other schema change):
|
||||
|
||||
* ``saved_chats`` — one row per conversation the owner explicitly
|
||||
Saves (the A10 extension, owner permission 2026-08-29):
|
||||
``/api/chat`` stays stateless and nothing is stored about a
|
||||
conversation that was not saved. ``title`` (the API-side auto-title —
|
||||
first question) is plain String(500) so a future rename needs no
|
||||
migration; ``messages`` is JSONB holding the exact ``bor.chat.v1``
|
||||
localStorage record shape (phase 14) so a saved chat restores
|
||||
pixel-identical through the existing ``renderStoredMessage`` path;
|
||||
``created_at``/``updated_at`` are stamped server-side (``updated_at``
|
||||
additionally bumps on every row update via the ORM ``onupdate``).
|
||||
No share-related columns — phase 51 adds ``share_token`` in ``0009``.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision = "0008"
|
||||
down_revision = "0007"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"saved_chats",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("title", sa.String(500), nullable=False),
|
||||
sa.Column("messages", postgresql.JSONB(), nullable=False),
|
||||
sa.Column(
|
||||
"created_at",
|
||||
sa.DateTime(timezone=True),
|
||||
server_default=sa.func.now(),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"updated_at",
|
||||
sa.DateTime(timezone=True),
|
||||
server_default=sa.func.now(),
|
||||
nullable=False,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("saved_chats")
|
||||
Reference in New Issue
Block a user