Skip to content

Conversation

@trichoplax
Copy link
Contributor

@trichoplax trichoplax commented Dec 3, 2025

Potentially irreversible change

This code change must not be merged without running the migration, because the code refers to a table that does not yet exist. The movement of data makes this change irreversible (at least for Rails' automatic rollback), and the fact that we use MySQL means that if the migration fails part way through it will be left in an intermediate state (for example, with a table created but no data moved). Separate up and down methods have been added to the migration, designed to handle rerunning or undoing the migration after an only partial success. However, please ensure backups are up to date before running this migration.


The ThreadFollower model was created to keep track of users following comment threads. Later it had a post_id field added to keep track of users following new threads on posts. This pull request splits out this later addition into a separate model NewThreadFollower.

Following discussion in Discord the migration file now covers all of:

  • Create the new_thread_followers table .
  • Move all rows containing a post_id from thread_followers to the new new_thread_followers table.
  • Remove the now unused post_id column from the thread_followers table.

I'm making this change so that #1548 can add a large number of rows (one per post) to the new_thread_followers table, rather than adding to the current combined table thread_followers. Waiting until after that large number of rows is added before splitting the table would require a much larger data movement between tables later (unless it is decided to never split the table, which I'm uncomfortable with since there's no reason for it to serve two independent purposes).

I'm not experienced in migrations so if there are obvious things that don't need to be mentioned in review, please mention them anyway.

@trichoplax trichoplax marked this pull request as draft December 3, 2025 21:51
@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.42%. Comparing base (44f1d22) to head (6d8e9a2).

Additional details and impacted files
Components Coverage Δ
controllers 74.69% <100.00%> (+0.03%) ⬆️
helpers 85.39% <ø> (+0.48%) ⬆️
jobs 79.24% <ø> (ø)
models 92.91% <100.00%> (+2.90%) ⬆️
tasks 61.11% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trichoplax trichoplax marked this pull request as ready for review December 6, 2025 01:55
@Oaphi Oaphi requested review from ArtOfCode-, Oaphi and cellio December 6, 2025 02:32
Oaphi
Oaphi previously requested changes Dec 7, 2025
Copy link
Member

@cellio cellio left a comment

Choose a reason for hiding this comment

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

There's an issue with the migration that @Oaphi will describe. Meanwhile, I've tested these changes (after locally making the migration fix) and behavior looks good -- the correct tables get updated on follow/unfollow on both posts and threads, and notifications get delivered as expected.

@cellio cellio requested a review from Oaphi December 7, 2025 18:02
@Oaphi Oaphi dismissed their stale review December 7, 2025 23:43

concern's been addressed

@cellio
Copy link
Member

cellio commented Dec 8, 2025

I tested down and up after the latest changes and it seemed to work, but also, my dev environment got a little messy from the earlier changes, so somebody else should provide final approval.

Copy link
Member

@Oaphi Oaphi left a comment

Choose a reason for hiding this comment

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

LGTM to me after the latest changes (tested, manual tests included), however, I am deferring to someone else to provide a final review given that I've made a couple of commits to the branch.

@cellio
Copy link
Member

cellio commented Dec 10, 2025

LGTM but want @ArtOfCode- to review. Also, hold merge until after we deploy; we have some other small things ready to ship, so let's get those out and then merge this just in case there are any issues that would require rollback. (I don't think there are, but this isn't user-facing so it doesn't need to be deployed right away.)


t.timestamps
end
add_index :new_thread_followers, [:user_id, :post_id], if_not_exists: true
Copy link
Member

Choose a reason for hiding this comment

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

I would add indexes here for user_id and post_id separately as well. We're likely to be querying for thread followers by post or by user as well as by both.

Copy link
Member

Choose a reason for hiding this comment

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

Revision after discussion in Discord: let's add an additional index for :post_id - the composite index will work for searches on :user_id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for explaining that the composite index works differently in MySQL. I've now added the index on post_id (and the corresponding removal for rollback).

@trichoplax trichoplax marked this pull request as draft December 12, 2025 15:25
@trichoplax trichoplax marked this pull request as ready for review December 12, 2025 22:13
@trichoplax
Copy link
Contributor Author

I'm avoiding merging

I'm waiting until potential problems in the develop branch are resolved / ruled out:

https://discord.com/channels/634104110131445811/668890340199235613/1452154459223228518

@trichoplax trichoplax marked this pull request as draft December 21, 2025 08:20
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.

5 participants