Skip to content

fix: correct the remaining per-dialect attributeToSQL bugs - #18428

Merged
WikiRik merged 3 commits into
wikirik-agent/attributes-to-sql-fixesfrom
wikirik-agent/attributes-to-sql-latent-bugs
Sep 19, 2026
Merged

WikiRik merged 3 commits into
wikirik-agent/attributes-to-sql-fixesfrom
wikirik-agent/attributes-to-sql-latent-bugs

Conversation

@wikirik-agent

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

Copy link
Copy Markdown
Contributor

Description of Changes

Fourth of the stack re-implementing #17121, stacked on #18400.

The per-dialect bugs that are left once the defaults (18427) and the options contract (#18400) are fixed. Each was verified against a real server rather than from reading the source, where a server was available.

Replaces #18402, which GitHub closed as merged when the stack was reordered — the branch and its commits are unchanged, nothing landed on main.

fix(ibmi,oracle): correct two per-dialect attributeToSQL bugs

oracle had 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.

ibmi computed an attributeString that both following branches overwrote.

fix(mssql,oracle): stop attributeToSQL from modifying 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. Two regression tests pin it: one asserts the attribute is unchanged after the call, the other that the same data type produces the same SQL twice.

meta: update the pinned TODOs to match what is still broken

Removes the notes describing behaviour this stack fixed, and corrects two that were wrong: db2 and mssql drop the referential actions of repeated references to the same table on purpose, because both servers reject more than one cascading constraint to a table. Only db2's extra rule for unique attributes has no known justification, so that one keeps a TODO.

Not changed, and why

  • sqlite3 ignoring attribute.comment — SQLite has no COMMENT syntax at all, so there is nothing to emit. Not a bug.
  • Comment escaping on postgres, db2 and mssql — every consumer that extracts the in-band COMMENT marker already escapes it. Escaping at the source (as fix: overhaul test suite of attribute(s)ToSQL #17121 does) would double-escape, and is what caused that PR to leak N'FooBar' into describeTable. Keeps a TODO.

Verification

All nine dialect unit suites pass at every commit in this PR, with clean eslint, clean prettier, and clean tsc on both --noEmit and test/tsconfig.json. Integration suites for the stack as a whole run against real servers: mssql 411 passing, oracle 388 passing (needs TZ=UTC), 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. ibmi remains unverified.

List of Breaking Changes

None. oracle's self-referential-constraint warning now actually fires, which means a self-referencing column loses its ON DELETE clause as the code always intended.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved SQL generation reliability across IBM i, Microsoft SQL Server, and Oracle.
    • Prevented schema attribute definitions from being modified during SQL generation.
    • Ensured repeated use of the same data type produces consistent SQL.
    • Improved handling of self-referential constraints and incomplete Oracle reference settings.
    • Standardized Oracle numeric and unsigned attribute handling.
  • Tests

    • Added regression coverage for input immutability and consistent repeated SQL generation.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: f2f350ef-f97d-451b-8435-6a0878c9e282

📥 Commits

Reviewing files that changed from the base of the PR and between 4095bd8 and c12bc68.

📒 Files selected for processing (3)
  • packages/ibmi/src/query-generator.js
  • packages/mssql/src/query-generator.js
  • packages/oracle/src/query-generator.js

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

attributeToSQL handling now avoids selected input mutations, removes redundant type conversion, and adjusts Oracle constraint checks. Core tests add regression coverage for attribute preservation and repeated SQL generation.

Changes

Attribute-to-SQL handling

Layer / File(s) Summary
Dialect attribute handling
packages/mssql/src/query-generator.js, packages/oracle/src/query-generator.js
MSSQL and Oracle shallow-copy plain attributes before processing. Oracle safely reads optional reference metadata, uses isSameTable, removes its dedicated DOUBLE path, and avoids mutating unsigned type options.
IBM i template assignment
packages/ibmi/src/query-generator.js
IBM i assigns template through the ENUM or non-ENUM conversion branch without the redundant initial conversion.
Core regression coverage and test comments
packages/core/test/unit/query-generator/attribute-to-sql.test.ts, packages/core/test/unit/query-generator/attributes-to-sql.test.ts
Core tests verify that attributes retain referential actions and that repeated SQL generation returns the same result. Related TODO comments are removed or clarified.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Suggested reviewers: wikirik

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main changes: fixing remaining per-dialect attributeToSQL bugs.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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 force-pushed the wikirik-agent/attributes-to-sql-latent-bugs branch from 4095bd8 to c12bc68 Compare September 19, 2026 07:32
wikirik-agent and others added 3 commits September 19, 2026 09:49
oracle had a branch testing `attribute.type === 'DOUBLE'`, which only matches
the raw string, and then called `toSql()` on that string. Reaching it threw a
TypeError. A raw string type now falls through to the general branch like every
other one. Its self-referential check compared against `references.tableName`,
which v7 never sets — it uses `references.table` — so the check never fired. It
now goes through `isSameTable`, as mssql's equivalent does.

ibmi computed an `attributeString` that both following branches overwrote.

Co-Authored-By: Claude Opus 5 <[email protected]>
mssql and oracle cleared onDelete and onUpdate on the caller's attribute
for self-referencing columns, and oracle switched off `unsigned` on the
shared data type, so a second call with the same type lost its CHECK
constraint. Oracle's integer types never render UNSIGNED, so the flag
only needs to be read.

Co-Authored-By: Claude Opus 5 <[email protected]>
Removes the notes describing behaviour this branch fixed, and corrects two that
were wrong: db2 and mssql drop the referential actions of repeated references
to the same table on purpose, because both servers reject more than one
cascading constraint to a table. Only db2's extra rule for unique attributes
has no known justification, so that one keeps a TODO.

Co-Authored-By: Claude Opus 5 <[email protected]>
@WikiRik
WikiRik force-pushed the wikirik-agent/attributes-to-sql-latent-bugs branch from c12bc68 to 6b35400 Compare September 19, 2026 07:49
@WikiRik
WikiRik merged commit 4cbadbd into main Sep 19, 2026
76 checks passed
@WikiRik
WikiRik deleted the wikirik-agent/attributes-to-sql-latent-bugs branch September 19, 2026 10:15
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.

2 participants