Skip to content

mysql - fix: moving to varbinary for key (fixes) - #2016

Merged
jaredwray merged 3 commits into
mainfrom
mysql---fix-moving-to-VARBINARY-for-key
Jul 18, 2026
Merged

mysql - fix: moving to varbinary for key (fixes)#2016
jaredwray merged 3 commits into
mainfrom
mysql---fix-moving-to-VARBINARY-for-key

Conversation

@jaredwray

Copy link
Copy Markdown
Owner

Please check if the PR fulfills these requirements

  • Followed the Contributing and Code of Conduct guidelines.
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
mysql - fix: moving to varbinary for key (fixes)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request migrates the MySQL adapter to use byte-exact VARBINARY columns for keys and namespaces, validating character limits in Unicode code points before encoding. It also reorders the composite index to (namespace, id) for improved query performance. The review feedback highlights a critical issue in both the adapter initialization and the migration script: using some() to check if columns need migration triggers a redundant and potentially unsafe conversion of both columns even if only one needs it. It is recommended to check and migrate each column individually.

Comment thread storage/mysql/src/index.ts Outdated
Comment thread storage/mysql/scripts/migrate-v6.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ec42e7adc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread storage/mysql/src/index.ts Outdated
Comment on lines +285 to +287
const keyByteLength = this._keyLength * 4;
const namespaceByteLength = this._namespaceLength * 4;
const createTable = `CREATE TABLE IF NOT EXISTS ${tableEsc}(id VARBINARY(${keyByteLength}) NOT NULL, value TEXT, namespace VARBINARY(${namespaceByteLength}) NOT NULL DEFAULT '', expires BIGINT UNSIGNED DEFAULT NULL, UNIQUE INDEX ${indexName} (namespace, id), INDEX ${expiresIndexName} (expires))`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject key-length combinations that exceed MySQL's index limit

When keyLength + namespaceLength exceeds 768, multiplying both limits by four makes the composite UNIQUE INDEX (namespace, id) larger than InnoDB's 3072-byte maximum, so adapter initialization fails. The documented keyLength: 512, namespaceLength: 512 combination produces a 4096-byte key and cannot create the table or complete migration; validate the combined limits or use an index representation that remains within MySQL's limit.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 40455eaa. The adapter constructor, keyLength and namespaceLength setters, and migration script now reject configurations where (keyLength + namespaceLength) * 4 exceeds the 3072-byte composite-index limit, before schema changes begin. The invalid 512 + 512 example was corrected in the README and regression tests cover both code paths.

Comment thread storage/mysql/src/index.ts Outdated
Comment thread storage/mysql/src/index.ts Outdated
…-VARBINARY-for-key

# Conflicts:
#	storage/mysql/README.md
#	storage/mysql/scripts/migrate-v6.ts
#	storage/mysql/src/index.ts
#	storage/mysql/test/test.ts
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6e519b4) to head (40455ea).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #2016   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           55        55           
  Lines         4885      4905   +20     
  Branches       784       786    +2     
=========================================
+ Hits          4885      4905   +20     

☔ 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.

@jaredwray
jaredwray merged commit f579073 into main Jul 18, 2026
14 checks passed
@jaredwray
jaredwray deleted the mysql---fix-moving-to-VARBINARY-for-key branch July 18, 2026 16:02
This was referenced Aug 3, 2026
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.

1 participant