Skip to content

docs(database): describe auto-increment columns outside the primary key - #196

Open
roxblnfk wants to merge 2 commits into
2.xfrom
docs/175-non-pk-auto-increment
Open

roxblnfk wants to merge 2 commits into
2.xfrom
docs/175-non-pk-auto-increment

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

🔍 What was changed

Primary-key auto-increment was already covered; this documents auto-incremented columns that are not the primary key.

  • database/declaration.md: a new "Auto-increment Columns Outside the Primary Key" section with per-driver behaviour — PostgreSQL serial() / bigSerial() / smallSerial() (Adding the ability to use serial without primary key database#106, 2.5.0); MySQL, where since cycle/database 2.23.4 (fix(MySQL): keep auto-increment columns out of the primary key database#275) an autoIncrement: true column stays out of the primary key and needs its own index, written into CREATE TABLE; no support on SQLite and SQL Server.
  • annotated/entity.md: entity examples for a PostgreSQL serial column and a MySQL autoIncrement column with a unique index, how the value is read back (RETURNING on PostgreSQL; on MySQL the field stays null until the entity is reloaded), and what happens on other drivers.

Review notes

  • 2.23.4 is the pending release-please version (chore(2.x): release 2.23.4 database#276); merge this after that release is out.
  • On MySQL the counter can be added only with a new table: adding it to an existing one still fails with error 1075, because the column and its index are added by separate statements. The docs say so without promising a version.

Checklist

  • Closes Write about auto increment #175
  • How was this tested:
    • PostgreSQL 17 and MySQL 8.0: schema and ORM paths, against cycle/database 2.x (with #275), cycle/orm 2.x, cycle/annotated 4.x
    • SQLite and the column DDL every driver renders

Serial columns without a primary key (cycle/database#106, 2.5.0) were undocumented, and the per-driver behaviour differs a lot: only PostgreSQL has a real non-PK counter, MySQL folds an AUTO_INCREMENT column into the primary key, SQLite and SQL Server have no option for it (#175).

Assisted-By: Claude Opus 5.5
…mary key

cycle/database#275 (cycle/database 2.23.4) keeps an autoIncrement column out of the primary key on MySQL, so the section now shows a counter with its own index instead of the composite-key workaround. Adding such a column to an existing table still fails with error 1075, so the docs keep it to new tables.

Assisted-By: Claude Opus 5.5
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.

Write about auto increment

1 participant