Skip to content

fix: correct the remaining per-dialect attributeToSql bugs - #18402

Merged
wikirik-agent merged 0 commit into
wikirik-agent/attributes-to-sql-typescriptfrom
wikirik-agent/attributes-to-sql-latent-bugs
Sep 18, 2026
Merged

wikirik-agent merged 0 commit into
wikirik-agent/attributes-to-sql-typescriptfrom
wikirik-agent/attributes-to-sql-latent-bugs

Conversation

@wikirik-agent

@wikirik-agent wikirik-agent commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Description of Changes

Fourth and last of the stack re-implementing #17121, stacked on #18401.

These are the per-dialect bugs found while converting the nine attributeToSql implementations to TypeScript. Unlike the earlier PRs in the stack, every claim here was verified against a real server (SQL Server 2025, Db2 LUW 12.1.4, Oracle 23.26 Free, MySQL 8.4, MariaDB 11.6) rather than from reading the source.

mysql — DEFAULT was silently dropped for BLOB, TEXT, GEOMETRY and JSON

MySQL accepts a default on those types as long as it is written as an expression, i.e. wrapped in parentheses, since 8.0.13. The minimum supported version is 8.0.20, so every supported server can take one.

The drop is now a parenthesisation, so the value reaches the server:

-- before:  `json` JSON
-- after:   `json` JSON DEFAULT (CAST('null' AS JSON))

Verified end to end: the column is created and the value round-trips.

Worth noting the guard sat before the existing BaseSqlExpression parenthesisation, so the MySQL 8.0.13 expression-default support already in the codebase was unreachable for exactly the types that needed it.

mariadb — same drop, but MariaDB has no such restriction at all

MariaDB has accepted defaults on BLOB/TEXT since 10.2.1 (MDEV-10134) and the minimum supported version is 10.4.30, so the list is removed outright rather than converted. Verified: bare TEXT DEFAULT 'abc', BLOB, JSON and GEOMETRY defaults are all accepted.

mariadb also emitted expression defaults unparenthesised, which MariaDB rejects for anything that is not a bare function call — DEFAULT 1+1 fails, DEFAULT (1+1) works. Those are now parenthesised as they already were on mysql, which is why three create-table expectations change.

oracle — two branches that could never have worked

  • else if (attribute.type && attribute.type === 'DOUBLE') only matches the raw string 'DOUBLE', and then calls .toSql() on it, which a string does not have. Reaching it threw a TypeError. DataTypes.DOUBLE renders as BINARY_DOUBLE or DOUBLE PRECISION and never takes this path. A raw string type now falls through to the general branch like every other one.
  • The self-referential-constraint check compared Model.tableName against references.tableName, but v7 references use references.table, so the comparison was always against undefined and the check never fired. It now goes through isSameTable, as mssql's equivalent already does.

mssql and oracle — attributeToSql modified its input

Both cleared onDelete / onUpdate on the caller's attribute object for self-referencing columns (oracle's check only started firing with the fix above). oracle also set unsigned to false on the shared data type, so a second call with the same type silently lost its CHECK (... >= 0). Both now work on a copy; oracle's integer types never render UNSIGNED, so the flag only needs to be read.

ibmi — dead local

attributeString was computed and then overwritten by both following branches.

Not changed, and why

  • sqlite3 ignoring attribute.comment — I had this on my list, but SQLite has no COMMENT syntax at all, so there is nothing to emit. Not a bug.
  • snowflake and ibmi typeWithoutDefault — left alone. I have no Snowflake account and no Db2 for i server, and after finding that five of the seven lists were wrong I did not want to change two more on documentation alone. Both are now the only remaining lists.

Verification

  • All nine dialect unit suites pass (2,296–2,906 tests each), clean eslint, clean tsc on both configs.
  • Integration suites run against real servers: mssql 411 passing, oracle 388 passing, db2 19 passing on the query-interface suite. Oracle needs TZ=UTC; four timestamp tests otherwise fail on a host in CEST, unrelated to this change. One db2 run hit an SQL0911N deadlock in an after each hook and passed on rerun.

List of Breaking Changes

mysql and mariadb now emit a DEFAULT clause for column types where they previously emitted none. A model that declared a defaultValue on a TEXT/BLOB/JSON/GEOMETRY column silently got no default before and will now get the one it asked for.

Replaces #18369, which was opened from a fork before stacked PRs were possible.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wikirik-agent wikirik-agent changed the title wikirik agent/attributes to sql latent bugs fix: correct the remaining per-dialect attributeToSql bugs Sep 17, 2026
@wikirik-agent
wikirik-agent force-pushed the wikirik-agent/attributes-to-sql-latent-bugs branch 2 times, most recently from fd9e289 to 1cab5f2 Compare September 18, 2026 20:36
@wikirik-agent
wikirik-agent merged commit 4095bd8 into main Sep 18, 2026
@wikirik-agent
wikirik-agent deleted the wikirik-agent/attributes-to-sql-latent-bugs branch September 18, 2026 21:23
@wikirik-agent
wikirik-agent force-pushed the wikirik-agent/attributes-to-sql-latent-bugs branch from 1cab5f2 to 4095bd8 Compare September 18, 2026 21:23
@wikirik-agent
wikirik-agent restored the wikirik-agent/attributes-to-sql-latent-bugs branch September 18, 2026 21:28
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.

1 participant