feat: persist cleaned question insights
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
"""persist cleaned question insights
|
||||
|
||||
Revision ID: 0020_question_insight_persistence
|
||||
Revises: 0019_periodic_reports
|
||||
Create Date: 2026-07-31 00:00:00.000000
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = "0020_question_insight_persistence"
|
||||
down_revision = "0019_periodic_reports"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"sys_question_insight_cleaned_question",
|
||||
sa.Column(
|
||||
"id",
|
||||
sa.BigInteger().with_variant(sa.Integer(), "sqlite"),
|
||||
primary_key=True,
|
||||
autoincrement=True,
|
||||
),
|
||||
sa.Column("message_id", sa.BigInteger(), nullable=False),
|
||||
sa.Column("session_id", sa.BigInteger(), nullable=False),
|
||||
sa.Column("user_id", sa.BigInteger(), nullable=False),
|
||||
sa.Column("part_index", sa.Integer(), nullable=False),
|
||||
sa.Column("cleaner_version", sa.String(length=20), nullable=False),
|
||||
sa.Column("source_hash", sa.String(length=64), nullable=False),
|
||||
sa.Column("cleaned_text", sa.Text(), nullable=False),
|
||||
sa.Column("normalized_text", sa.Text(), nullable=False),
|
||||
sa.Column("category", sa.String(length=50), nullable=False, server_default="other"),
|
||||
sa.Column("tokens_json", sa.Text(), nullable=False),
|
||||
sa.Column("accepted", sa.Integer(), nullable=False, server_default="1"),
|
||||
sa.Column("filtered_reason", sa.String(length=100), nullable=True),
|
||||
sa.Column("source_created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
|
||||
sa.ForeignKeyConstraint(
|
||||
["message_id"],
|
||||
["sys_chat_message.id"],
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
"message_id",
|
||||
"cleaner_version",
|
||||
"part_index",
|
||||
name="uq_question_insight_message_version_part",
|
||||
),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_sys_question_insight_cleaned_question_session_id",
|
||||
"sys_question_insight_cleaned_question",
|
||||
["session_id"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_sys_question_insight_cleaned_question_user_id",
|
||||
"sys_question_insight_cleaned_question",
|
||||
["user_id"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_question_insight_version_accepted_created",
|
||||
"sys_question_insight_cleaned_question",
|
||||
["cleaner_version", "accepted", "source_created_at"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_question_insight_category_created",
|
||||
"sys_question_insight_cleaned_question",
|
||||
["category", "source_created_at"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_question_insight_session_created",
|
||||
"sys_question_insight_cleaned_question",
|
||||
["session_id", "source_created_at"],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(
|
||||
"ix_question_insight_session_created",
|
||||
table_name="sys_question_insight_cleaned_question",
|
||||
)
|
||||
op.drop_index(
|
||||
"ix_question_insight_category_created",
|
||||
table_name="sys_question_insight_cleaned_question",
|
||||
)
|
||||
op.drop_index(
|
||||
"ix_question_insight_version_accepted_created",
|
||||
table_name="sys_question_insight_cleaned_question",
|
||||
)
|
||||
op.drop_index(
|
||||
"ix_sys_question_insight_cleaned_question_user_id",
|
||||
table_name="sys_question_insight_cleaned_question",
|
||||
)
|
||||
op.drop_index(
|
||||
"ix_sys_question_insight_cleaned_question_session_id",
|
||||
table_name="sys_question_insight_cleaned_question",
|
||||
)
|
||||
op.drop_table("sys_question_insight_cleaned_question")
|
||||
Reference in New Issue
Block a user