Skip to content

fix(MySQL): keep auto-increment columns out of the primary key - #275

Merged
roxblnfk merged 2 commits into
2.xfrom
fix/274-mysql-autoincrement-non-pk
Oct 5, 2026
Merged

roxblnfk merged 2 commits into
2.xfrom
fix/274-mysql-autoincrement-non-pk

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Oct 5, 2026

Copy link
Copy Markdown
Member

🔍 What was changed

  • integer() / bigInteger() with autoIncrement: true no longer end up in the primary key on MySQL: setPrimaryKeys(['id']) stays ['id'], and the column keeps its declared abstract type.
  • Reflecting an existing table returns its real primary key; an AUTO_INCREMENT column outside it is reported as integer / bigInteger, so saving the same declaration again produces no diff.
  • Indexes on an AUTO_INCREMENT column that does not lead the primary key are written into 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 a SchemaException naming it.
  • smallPrimary() now works on MySQL: it used to be created without the primary key and failed with 1075.

Review notes

  • MySQL columns now carry an internal isPrimary flag, the same model Postgres uses for serial; only primary-key columns reverse-map to primary / smallPrimary / bigPrimary. The flag is excluded from column comparison: primary key changes are already compared at the table level.
  • Adding an AUTO_INCREMENT column to an existing table still creates its index after ALTER TABLE … ADD COLUMN and fails the same way. That path is unchanged here.

Checklist

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>
@roxblnfk
roxblnfk requested review from a team as code owners October 5, 2026 10:03
@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.71%. Comparing base (75fb8f2) to head (d6eea82).

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

@roxblnfk
roxblnfk merged commit 90219cf into 2.x Oct 5, 2026
31 checks passed
@roxblnfk
roxblnfk deleted the fix/274-mysql-autoincrement-non-pk branch October 5, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MySQL autoIncrement column is always added to the primary key

1 participant