Skip to content

Conversation

@lpi-tn
Copy link
Collaborator

@lpi-tn lpi-tn commented Jan 16, 2026

This pull request introduces significant improvements to the user-related data model and database schema, focusing on enhanced support for inferred users, chat message tracking, and data collection campaigns. It adds a new Alembic migration, updates models, and introduces comprehensive CRUD tests for these changes. Additionally, it updates configuration and environment files for better usability and safety.

Database and Model Enhancements:

  • Added a new DataCollectionCampaignManagement model and corresponding table to track data collection campaigns, including fields for activity status and end date. [1] [2]
  • Refactored the ChatMessage model to associate messages with inferred_user_id instead of user_id, and added new fields: conversation_id and role. Updated relationships accordingly. [1] [2] [3]
  • Added an is_clicked boolean column to the ReturnedDocument model to track user interactions with returned documents. [1] [2]

Testing Improvements:

  • Introduced a new test suite in tests/test_user_related.py to verify CRUD operations for all major user-related models, including the new and updated fields.

Migration and Environment Safety:

  • Added a new Alembic migration script to create and modify relevant tables and columns, including safe handling of foreign key relationships and schema changes.
  • Updated Alembic environment configuration to warn and require confirmation when running migrations against a production database, reducing the risk of accidental changes. [1] [2]

Configuration Updates:

  • Added a .env.example file with recommended environment variables for database connectivity and logging.
  • Bumped the project version in pyproject.toml to 1.3.0 to reflect these changes.

@lpi-tn lpi-tn requested a review from Copilot January 16, 2026 16:45
@lpi-tn lpi-tn merged commit 2eeafb6 into main Jan 16, 2026
4 checks passed
@lpi-tn lpi-tn deleted the Feature/Prepare-data-collection branch January 16, 2026 16:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces database schema changes and a new model to support data collection campaigns, refactors the ChatMessage model to use inferred users, and adds click tracking for returned documents.

Changes:

  • Added DataCollectionCampaignManagement model to track data collection campaigns with activation status and end dates
  • Refactored ChatMessage to associate with inferred_user_id instead of user_id, and added conversation_id and role fields
  • Added is_clicked field to ReturnedDocument for tracking user interactions

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
welearn_database/data/models/user_related.py Updated ChatMessage to use inferred_user_id, added role and conversation_id fields; added is_clicked to ReturnedDocument; added DataCollectionCampaignManagement model
welearn_database/alembic/versions/2ad4895b2674_data_collection.py Migration script to create data_collection_campaign_management table and modify chat_message and returned_document tables
welearn_database/alembic/env.py Added production database safety check with confirmation prompt before running migrations
tests/test_user_related.py Comprehensive CRUD tests for all user-related models including new DataCollectionCampaignManagement and updated ChatMessage fields
pyproject.toml Version bump to 1.3.0
.env.example Added example environment configuration for database connectivity and logging

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if "prod" in os.getenv("PG_HOST").lower():
print("Connecting to production database for migrations!")
input("Press Enter to continue...")
elif "dev" in os.getenv("PG_HOST" "").lower():
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma between arguments in os.getenv call. Should be os.getenv('PG_HOST', '') instead of os.getenv('PG_HOST' '').

Suggested change
elif "dev" in os.getenv("PG_HOST" "").lower():
elif "dev" in os.getenv("PG_HOST", "").lower():

Copilot uses AI. Check for mistakes.
),
nullable=False,
)
is_clicked: Mapped[bool] = mapped_column(default=False)
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value should be set using server_default instead of default for consistency with database-level defaults and to ensure the value is set even when rows are inserted directly via SQL.

Suggested change
is_clicked: Mapped[bool] = mapped_column(default=False)
is_clicked: Mapped[bool] = mapped_column(default=False, server_default="false")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants