-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/focus group data collection #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a840351
54c6ca7
90a944b
24621dd
aae9373
7946d1f
751b3d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| """data collection for focus group | ||
|
|
||
| Revision ID: 9b4f1da0c1f2 | ||
| Revises: 2ad4895b2674 | ||
| Create Date: 2026-02-23 18:11:55.857517 | ||
|
|
||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "9b4f1da0c1f2" | ||
| down_revision: Union[str, None] = "2ad4895b2674" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.add_column( | ||
| "chat_message", | ||
| sa.Column( | ||
| "is_retrieved_by_user", | ||
| sa.Boolean(), | ||
| nullable=False, | ||
| default=False, | ||
| server_default="False", | ||
| ), | ||
| schema="user_related", | ||
| ) | ||
| op.add_column( | ||
| "chat_message", | ||
| sa.Column("original_feature_name", sa.String(), nullable=True), | ||
| schema="user_related", | ||
| ) | ||
| op.create_table( | ||
| "filter_used_in_query", | ||
| sa.Column( | ||
| "id", sa.Uuid(), server_default=sa.func.gen_random_uuid(), nullable=False | ||
| ), | ||
| sa.Column("message_id", sa.Uuid(), nullable=False), | ||
| sa.Column( | ||
| "filter_type", | ||
| postgresql.ENUM( | ||
| "sdg", | ||
| "source", | ||
| name="filter_type", | ||
| schema="user_related", | ||
| ), | ||
| nullable=False, | ||
| ), | ||
| sa.Column("filter_value", sa.String(), nullable=False), | ||
| sa.ForeignKeyConstraint( | ||
| ["message_id"], | ||
| ["user_related.chat_message.id"], | ||
| name="filter_used_in_query_message_id_fkey", | ||
| ), | ||
| sa.PrimaryKeyConstraint("id"), | ||
| schema="user_related", | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_column("chat_message", "is_retrieved_by_user", schema="user_related") | ||
| op.drop_column("chat_message", "original_feature_name", schema="user_related") | ||
| op.drop_constraint( | ||
| "filter_used_in_query_message_id_fkey", | ||
| "filter_used_in_query", | ||
| schema="user_related", | ||
| type_="foreignkey", | ||
| ) | ||
| op.drop_table("filter_used_in_query", schema="user_related") | ||
| op.execute("DROP TYPE IF EXISTS user_related.filter_type") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,10 @@ | |
| from uuid import UUID | ||
|
|
||
| from sqlalchemy import ForeignKey, func, types | ||
| from sqlalchemy.dialects.postgresql import TIMESTAMP | ||
| from sqlalchemy.dialects.postgresql import ENUM, TIMESTAMP | ||
| from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
|
||
| from welearn_database.data.enumeration import DbSchemaEnum | ||
| from welearn_database.data.enumeration import DbSchemaEnum, FilterType | ||
| from welearn_database.data.models.document_related import WeLearnDocument | ||
|
|
||
| from . import Base | ||
|
|
@@ -96,6 +96,10 @@ class ChatMessage(Base): | |
| ) | ||
| role: Mapped[str] | ||
| textual_content: Mapped[str] | ||
| is_retrieved_by_user: Mapped[bool] = mapped_column( | ||
| default=False, server_default="False" | ||
| ) | ||
| original_feature_name: Mapped[str | None] | ||
|
|
||
| created_at: Mapped[datetime] = mapped_column( | ||
| TIMESTAMP(timezone=False), | ||
|
|
@@ -134,6 +138,7 @@ class ReturnedDocument(Base): | |
| nullable=False, | ||
| ) | ||
| is_clicked: Mapped[bool] = mapped_column(default=False) | ||
|
|
||
| welearn_document: Mapped["WeLearnDocument"] = relationship() | ||
| chat_message: Mapped["ChatMessage"] = relationship() | ||
|
|
||
|
|
@@ -240,3 +245,27 @@ class EndpointRequest(Base): | |
| server_default="NOW()", | ||
| ) | ||
| session = relationship("Session", foreign_keys=[session_id]) | ||
|
|
||
|
|
||
| class FilterUsedInQuery(Base): | ||
| __tablename__ = "filter_used_in_query" | ||
| __table_args__ = {"schema": DbSchemaEnum.USER_RELATED.value} | ||
|
|
||
| id: Mapped[UUID] = mapped_column( | ||
| types.Uuid, primary_key=True, nullable=False, server_default="gen_random_uuid()" | ||
| ) | ||
| message_id = mapped_column( | ||
| types.Uuid, | ||
| ForeignKey(f"{DbSchemaEnum.USER_RELATED.value}.chat_message.id"), | ||
| nullable=False, | ||
| ) | ||
| filter_type: Mapped[str] = mapped_column( | ||
|
Comment on lines
+258
to
+262
|
||
| ENUM( | ||
| *(e.value.lower() for e in FilterType), | ||
| name="filter_type", | ||
| schema=DbSchemaEnum.USER_RELATED.value, | ||
| ), | ||
| ) | ||
| filter_value: Mapped[str] | ||
|
Comment on lines
+251
to
+269
|
||
|
|
||
| chat_message: Mapped["ChatMessage"] = relationship() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReturnedDocument.original_feature_nameandReturnedDocument.conversation_idare declared withoutmapped_column(...), unlike the other columns in this model. This relies on type inference and may lead to inconsistent DDL (e.g., missingtypes.Uuidconfiguration for UUIDs) compared to the rest of the schema. Define these explicitly withmapped_column(includingtypes.Uuidforconversation_id) and decide/declarenullable/defaults to match the intended DB constraints.