Skip to content

fix: update MySQL logic to use 0 for non-pinned posts instead of NULL#47

Merged
Alam-2U merged 1 commit intorelease-ulmofrom
COSMO2-902
May 6, 2026
Merged

fix: update MySQL logic to use 0 for non-pinned posts instead of NULL#47
Alam-2U merged 1 commit intorelease-ulmofrom
COSMO2-902

Conversation

@Alam-2U
Copy link
Copy Markdown
Collaborator

@Alam-2U Alam-2U commented May 6, 2026

Description

After migrating data from MongoDB to MySQL, the pinned column in the forum_commentthread table had inconsistent values:

  • Migrated posts: 0 (non-pinned) and 1 (pinned)
  • Newly created posts: NULL for non-pinned

Since sorting prioritizes the pinned column before last_activity_at, this inconsistency caused incorrect ordering. Non-pinned migrated posts (0) were always appearing above newly created non-pinned posts (NULL), regardless of their recent activity (1 → 0 → NULL).

Root Cause

Newly created posts were not assigning a default value to the pinned column, resulting in NULL values instead of 0 for non-pinned posts.

Changes Made

  • Updated logic to set pinned = 0 for non-pinned posts instead of NULL

Post Task

  • Backfill existing records to replace NULL values with 0
  • Enforce schema constraint: pinned TINYINT(1) NOT NULL DEFAULT 0

Ticket

COSMO2-902

Copy link
Copy Markdown

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

Fixes inconsistent pinned values in the MySQL CommentThread model so newly created non-pinned threads use 0/False instead of NULL, preventing incorrect ordering when sorting by pinned-first.

Changes:

  • Make CommentThread.pinned default to False (and update MySQL creation logic accordingly).
  • Update MongoDB→MySQL migration helper to default missing pinned values to False.
  • Adjust MySQL model test expectations and bump package version.

Reviewed changes

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

Show a summary per file
File Description
tests/test_backends/test_mysql/test_models.py Updates thread creation test to expect pinned=False rather than None.
forum/migration_helpers.py Defaults missing pinned values to False during thread migration/update.
forum/backends/mysql/models.py Changes pinned field to default to False and removes nullable typing/field config.
forum/backends/mysql/api.py Forces pinned=False on MySQL thread creation to avoid NULL inserts.
forum/__init__.py Bumps version to 0.5.8.

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

Comment thread forum/backends/mysql/models.py
Comment thread forum/backends/mysql/api.py
@Alam-2U Alam-2U merged commit e9d179b into release-ulmo May 6, 2026
17 checks passed
@Alam-2U Alam-2U deleted the COSMO2-902 branch May 6, 2026 07:49
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.

3 participants