Repository navigation
fix(mssql): cast int IDENTITY to serial, not bigserial - #1743
Merged
Merged
Conversation
MSSQL "int" is 32-bit; the previous default cast to "bigserial" (64-bit) changed the column type unnecessarily, wasted space, and broke the Node.js pg driver (which returns strings instead of numbers for int8). v3: change the :auto-increment cast rule for "int" from "bigserial" to "serial". The "bigint :auto-increment" → "bigserial" rule is correct and unchanged. "smallint :auto-increment" → "smallserial" and "tinyint :auto-increment" → "serial" were already correct. v4: mssql.clj hardcoded "bigserial" for every IDENTITY column regardless of source type. Now uses "bigserial" only for bigint IDENTITY, "serial" for all other integer types (int, smallint, tinyint). Users who rely on the old bigserial behaviour can override with a cast rule: type int to bigserial auto-increment drop default Fixes #1590. Closes #1596.
pg-type-for already handled "bigserial" as a pass-through native PG type. "serial" and "smallserial" were missing, so they fell through to the :else "text" branch — turning MSSQL int IDENTITY columns into "text" after the int→serial cast change, breaking sequence detection and FK constraints.
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.
Fixes #1590. Closes #1596. Cherry-picks the correct fix from @gnarlex.
Problem
MSSQL
intis 32-bit. The previous default cast tobigserial(64-bit) was wrong:pgdriver, which returns strings forint8values instead of JavaScript numbers, because JS cannot represent full 64-bit integers safelyFix
v3 (
src/sources/mssql/mssql-cast-rules.lisp): change theint :auto-incrementcast rule target frombigserialtoserial. The existing rules forbigint :auto-increment→bigserial,smallint :auto-increment→smallserial, andtinyint :auto-increment→serialwere already correct.v4 (
clojure/src/pgloader/source/mssql.clj): the source hardcoded"bigserial"for every IDENTITY column regardless of the source integer type. Now uses"bigserial"only forbigint IDENTITY, and"serial"for everything else (int,smallint,tinyint).Override
Users who relied on the old behaviour can restore it with a cast rule that matches only auto-increment
intcolumns: