Repository navigation
fix(MySQL): keep auto-increment columns out of the primary key - #275
Merged
Merged
Conversation
Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
An `integer(autoIncrement: true)` column was reverse-mapped to `primary`, so it was always added to the primary key, both when declared and when reflected from an existing table. Columns now carry an internal `isPrimary` flag, as Postgres serial columns do, and only real primary keys map to the `*Primary` types; this also makes `smallPrimary()` work on MySQL. MySQL rejects an AUTO_INCREMENT column without a key, so indexes on such columns go into CREATE TABLE, and a column with no key at all fails with a SchemaException instead of SQL error 1075. Fixes #274 Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #275 +/- ##
============================================
+ Coverage 95.61% 95.71% +0.10%
- Complexity 2230 2242 +12
============================================
Files 142 142
Lines 6341 6374 +33
============================================
+ Hits 6063 6101 +38
+ Misses 278 273 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔍 What was changed
integer()/bigInteger()withautoIncrement: trueno longer end up in the primary key on MySQL:setPrimaryKeys(['id'])stays['id'], and the column keeps its declared abstract type.integer/bigInteger, so saving the same declaration again produces no diff.CREATE TABLE, since MySQL rejects such a column without a key (error 1075). A column that is in neither the primary key nor an index now fails with aSchemaExceptionnaming it.smallPrimary()now works on MySQL: it used to be created without the primary key and failed with 1075.Review notes
isPrimaryflag, the same model Postgres uses forserial; only primary-key columns reverse-map toprimary/smallPrimary/bigPrimary. The flag is excluded from column comparison: primary key changes are already compared at the table level.ALTER TABLE … ADD COLUMNand fails the same way. That path is unchanged here.Checklist