Skip to content

Added an index on automated_email_recipients.mailgun_message_id#29539

Merged
EvanHahn merged 4 commits into
mainfrom
prefix-index-mailgun-id
Jul 22, 2026
Merged

Added an index on automated_email_recipients.mailgun_message_id#29539
EvanHahn merged 4 commits into
mainfrom
prefix-index-mailgun-id

Conversation

@EvanHahn

@EvanHahn EvanHahn commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

closes https://linear.app/ghost/issue/NY-1464
closes https://linear.app/ghost/issue/NY-1476

What

Adds an index to improve performance.

Along the way, had to add support for index prefixes in isMySQL.

Why

MySQL can't index long VARCHARs in full. You can solve this by hashing the value or by using an index prefix, which effectively only indexes the first N characters.

We chose the latter: an index prefix. We don't need uniqueness so it's okay if there's a little overlap.

The bulk of this PR adds support for those index prefixes, with the actual migration as a little sprinkle on top.

Test plan

Added several automated tests.

Also manually ran this SQL and checked the output, on both a fresh database and a migrated one:

SELECT * FROM information_schema.STATISTICS
WHERE table_name = 'automated_email_recipients'
AND column_name = 'mailgun_message_id';

I did not test this with real data on staging because (1) I didn't want to (2) I think it's relatively low-risk. Happy to do that if you think I should.

@github-actions github-actions Bot added the migration [pull request] Includes migration for review label Jul 22, 2026
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

It looks like this PR contains a migration 👀
Here's the checklist for reviewing migrations:

General requirements

  • ⚠️ Tested performance on staging database servers, as performance on local machines is not comparable to a production environment
  • Satisfies idempotency requirement (both up() and down())
  • Does not reference models
  • Filename is in the correct format (and correctly ordered)
  • Targets the next minor version
  • All code paths have appropriate log messages
  • Uses the correct utils
  • Contains a minimal changeset
  • Does not mix DDL/DML operations
  • Tested in MySQL and SQLite

Schema changes

  • Both schema change and related migration have been implemented
  • For index changes: has been performance tested for large tables
  • For new tables/columns: fields use the appropriate predefined field lengths
  • For new tables/columns: field names follow the appropriate conventions
  • Does not drop a non-alpha table outside of a major version

Data changes

  • Mass updates/inserts are batched appropriately
  • Does not loop over large tables/datasets
  • Defends against missing or invalid data
  • For settings updates: follows the appropriate guidelines

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9e3824a1-43cb-4289-85c9-07aa851b925b

📥 Commits

Reviewing files that changed from the base of the PR and between 50274f6 and 79dd6a6.

📒 Files selected for processing (2)
  • ghost/core/core/server/data/migrations/utils/schema.js
  • ghost/core/core/server/data/migrations/versions/6.54/2026-07-21-21-08-15-add-automated-email-recipients-mailgun-message-id-index.js

Walkthrough

Adds MySQL prefix-index support to schema commands, including generated index names and configurable column-prefix lengths. Configures a 31-character index for automated_email_recipients.mailgun_message_id and adds a reversible migration. Updates schema seeding and integrity expectations, with unit tests covering index-name generation across SQLite and MySQL.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding an index on automated_email_recipients.mailgun_message_id.
Description check ✅ Passed The description is directly related to the changeset and accurately explains the index addition and MySQL prefix support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch prefix-index-mailgun-id

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nx-cloud

nx-cloud Bot commented Jul 22, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 79dd6a6

Command Status Duration Result
nx run ghost:test:ci:integration ✅ Succeeded 3m 4s View ↗
nx run ghost:test:integration ✅ Succeeded 3m 12s View ↗
nx run ghost:test:legacy ✅ Succeeded 2m 58s View ↗
nx run ghost:test:e2e ✅ Succeeded 2m 43s View ↗
nx run-many -t test:unit -p ghost ✅ Succeeded 30s View ↗
nx run @tryghost/admin:build ✅ Succeeded 4s View ↗
nx run ghost-monorepo:lint:boundaries ✅ Succeeded 21s View ↗
nx run-many -t lint -p ghost,ghost-monorepo ✅ Succeeded 18s View ↗
nx run-many --target=build --projects=tag:publi... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-07-22 20:08:38 UTC

@EvanHahn
EvanHahn force-pushed the prefix-index-mailgun-id branch from dd4fae3 to ca1e40e Compare July 22, 2026 17:30
EvanHahn added 2 commits July 22, 2026 12:40
closes https://linear.app/ghost/issue/NY-1476

What
----

Adds support for [index prefixes in isMySQL][0].

This change should have no user impact.

Why
---

MySQL can't index long `VARCHAR`s in full. You can solve this by hashing
the value or by using an [index prefix][0], which effectively only
indexes the first *N* characters.

We'll want to do the latter in an upcoming patch, so let's add support
for it to our migration system (`addIndex`) and our table creation
system (`createTable`).

Notably, we have to do a little work to ensure that we generate the
index name the same way Knex does, that way `dropIndex` will work.
(Knex, unfortunately, doesn't expose this functionality directly, so we
add a test to ensure they're the same.)

[0]: https://dev.mysql.com/doc/refman/8.4/en/column-indexes.html#column-indexes-prefix
@EvanHahn
EvanHahn force-pushed the prefix-index-mailgun-id branch from ca1e40e to 50274f6 Compare July 22, 2026 17:40
@EvanHahn
EvanHahn requested a review from cmraible July 22, 2026 17:54
@EvanHahn
EvanHahn enabled auto-merge (squash) July 22, 2026 19:57
@EvanHahn
EvanHahn merged commit cb84320 into main Jul 22, 2026
46 checks passed
@EvanHahn
EvanHahn deleted the prefix-index-mailgun-id branch July 22, 2026 20:09
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.42105% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.80%. Comparing base (35e8331) to head (79dd6a6).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
ghost/core/core/server/data/schema/commands.js 70.27% 10 Missing and 1 partial ⚠️
.../core/server/data/schema/lib/default-index-name.js 65.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #29539      +/-   ##
==========================================
+ Coverage   74.53%   74.80%   +0.27%     
==========================================
  Files        1609     1611       +2     
  Lines      141475   141659     +184     
  Branches    17261    17320      +59     
==========================================
+ Hits       105443   105975     +532     
+ Misses      34998    34612     -386     
- Partials     1034     1072      +38     
Flag Coverage Δ
e2e-tests 76.90% <68.42%> (+0.30%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

migration [pull request] Includes migration for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants