Skip to content

Support AUTOINCREMENT in public creation APIs and CLI - #894

Open
MbappeWU wants to merge 1 commit into
simonw:mainfrom
MbappeWU:feat/autoincrement
Open

MbappeWU wants to merge 1 commit into
simonw:mainfrom
MbappeWU:feat/autoincrement

Conversation

@MbappeWU

@MbappeWU MbappeWU commented Oct 2, 2026 •

Copy link
Copy Markdown

The public creation APIs cannot request INTEGER PRIMARY KEY AUTOINCREMENT, even though the SQL builder already uses it internally to preserve existing tables during transforms. Ordinary integer primary keys allocate missing IDs, but may reuse a deleted maximum ID. This adds an explicit choice for the no-reuse behavior requested in #664.

Add autoincrement=True/False/None to the Python creation and insertion paths, including table defaults and lookup, and --autoincrement/--no-autoincrement to create-table, insert, upsert and transform. None keeps the current behavior; transformations preserve existing mode and sequence. Preview and execution use the same option. Upserts still require a primary key value in each record. Inserts and lookups reject an explicit mode that conflicts with an existing table, instead of changing its schema. Enabling the mode on an ordinary table starts tracking its current IDs; it cannot recover earlier deleted-ID history.

Validate the primary key and effective column type before replacement, added columns or extraction dependency tables can be created. Retain the existing quoting and sequence restoration paths. Include usage docs, generated CLI reference and an unreleased changelog entry.

Closes #664.

Validation:

  • Full suite: 1,564 passed / 16 skipped, in both default and SQLite autocommit modes. Baseline: 1,497 passed / 16 skipped.
  • The exact original DB and CLI modules with the same final AUTOINCREMENT tests: 66 failures / 2 passes, including the existing preservation test and the unchanged default-allocation case.
  • Installed wheel, real CLI child processes and on-disk SQLite: nine creation, invalid-replacement and mode-disable scenarios passed.
  • Mypy, Pyright, ty, flake8, Black, Cog and spelling checks passed. Sphinx HTML built with warnings treated as errors. Wheel/sdist bytes match the checked source.
  • Original fork workflows on the final commit: 48 Python/OS/numpy matrix jobs, two SQLite-version jobs and spelling all passed (51 jobs total): https://github.com/MbappeWU/sqlite-utils/actions/runs/37071539111

Prepared with Codex. Agent code and security reviews caught and corrected cached-mode and extraction side-effect cases; maintainer review is still required.

Upstream test, SQLite-version, coverage and spelling workflows are awaiting maintainer approval for this contribution. The repository documentation preview workflow succeeded.


📚 Documentation preview 📚: https://sqlite-utils--894.org.readthedocs.build/en/894/

@MbappeWU
MbappeWU marked this pull request as ready for review October 2, 2026 22:29
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.

Support AUTOINCREMENT keyword

1 participant