fix(db2): use DEFAULT for auto-increment columns in inserts - #18422
Draft
wikirik-agent wants to merge 1 commit into
Draft
wikirik-agent wants to merge 1 commit into
wikirik-agent wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5 <[email protected]>
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Pull Request Checklist
Description of Changes
On Db2,
Model.create({})failed when the only value to insert was the auto-increment primary key, e.g. a model without timestamps whose other columns are nullable:Db2 disabled
supports.autoIncrement.defaultValue, so core dropped thenullauto-increment column, and Db2 is the only dialect that supports neitherDEFAULT VALUESnorVALUES (), which left a bareINSERT INTO.bulkCreate([{}, {}])had its own problems. The Db2bulkInsertQueryoverride inserted ids from a counter kept on the query generator (INSERT INTO "Events" VALUES (1),(2)):SQL0117Nwhen the table had other columns;returning: trueit returnednullids.Db2 accepts
DEFAULTfor identity columns, also in multi-row inserts and insideFINAL TABLE.DEFAULT VALUES,VALUES ()and a bareVALUES (DEFAULT)on a table with several columns are rejected. So this PR:supports.autoIncrement.defaultValueand enablessupports.bulkDefaultfor Db2, so inserts use("id") VALUES (DEFAULT)like PostgreSQL;bulkInsertQuerywith the shared implementation, wrapped inSELECT * FROM FINAL TABLE (...)whenreturningis set, as the IBM i dialect already does. Bulk values are now also escaped with their attribute type.Replacing the override also means Db2 will get bulk-insert bind parameters from the shared implementation once #17752 lands, which covers the Db2 part of #18346. The two PRs touch the same Db2 method, so whichever merges second needs a small rebase.
Not changed: a Db2 model without any primary key still can't
create({}), because there is no column to set toDEFAULT.Tests
create({})andbulkCreate([{}, {}])on a model whose values all come from defaults. Onmainthey fail on Db2 withSQL0104NandSQL0117N.Worker.create({ id: 1 })workarounds inbelongs-to-many.test.jsare removed, and Db2 now shares the PostgreSQL SQL expectation inbulk-create.test.js.nullininsertQuery, and for default-only rows inbulkInsertQuerywith and withoutreturning. The old Db2 expectationVALUES (0),(NULL)insql/insert.test.jsis nowVALUES (0),(DEFAULT); theNULLversion fails on the server withSQL0407N.model/create,model/bulk-createandassociations/belongs-to-manypass on db2, postgres, mysql, mariadb, mssql, sqlite3 and oracle; the Db2 and IBM i unit suites pass.List of Breaking Changes
None.
🤖 Generated with Claude Code