Skip to content

meta: unify attributeToSQL and attributesToSQL test suites - #18366

Closed
wikirik-agent wants to merge 1 commit into
sequelize:mainfrom
wikirik-agent:attributes-to-sql-tests
Closed

wikirik-agent wants to merge 1 commit into
sequelize:mainfrom
wikirik-agent:attributes-to-sql-tests

Conversation

@wikirik-agent

Copy link
Copy Markdown
Contributor

Description of Changes

First of a stack re-implementing #17121, which is incomplete and has drifted ~11 months behind main (oracle did not exist when it was last touched).

This PR does the test consolidation only. It replaces the per-dialect attributesToSQL suites in test/unit/dialects/*/query-generator.test.js with two dialect-agnostic suites in test/unit/query-generator/, covering all nine dialects — including ibmi and mssql, which had no attributesToSQL coverage at all.

The expectations pin current behaviour exactly. No SQL changes. Behaviour that is wrong today is pinned as-is and marked with a TODO, so the follow-up PR's diff reads as a list of behaviour deltas rather than a rewrite.

Two supporting changes were needed:

  • sqlite3 gains an attributeToSQL method, extracted from attributesToSQL without changing its output (including the existing PRIMARY KEY AUTOINCREMENT ordering and the non-object passthrough branch). Every other dialect already has one; without it sqlite3 could not join the shared suite.
  • inlineErrorCause inspects non-error values instead of stringifying them. mssql and ibmi return null-prototype maps from attributesToSQL, and expectPerDialect builds its assertion message eagerly — String(nullPrototypeObject) throws Cannot convert object to primitive value. This is load-bearing, not cosmetic.

Closes #15533

What the new suites found

Expectations were generated from actual output across all nine dialects rather than written by hand, which surfaced a number of problems beyond the ones already flagged on #17121. All are pinned and TODO-marked here, and are the subject of the next PR:

  • attribute.type._binary no longer exists on v7 data types, so the "this type cannot have a default" guard is dead on six dialects.
  • mssql/db2/ibmi/oracle guard TEXT defaults with attribute.type !== 'TEXT', comparing a DataType instance to a string — it never matches.
  • Only postgres reads options.table; mysql/mariadb/snowflake/db2/ibmi read options.tableName. Passing the documented option name either throws (mariadb, mysql) or names the constraint undefined_..._foreign_idx (snowflake, db2, ibmi).
  • snowflake and ibmi embed an already-quoted column into the FK constraint name ("myTable_""myColumn""_foreign_idx"); db2 leaves the constraint name unquoted entirely.
  • sqlite3, snowflake and ibmi ignore withoutForeignKeyConstraints.
  • postgres dereferences options.schema / options.table / options.withoutForeignKeyConstraints unguarded, so attributeToSQL(attr) throws whenever the attribute has references.
  • postgres builds the COMMENT ON COLUMN column name from options.key, which addColumnQuery supplies but attributesToSQL does not.
  • db2 and mssql silently drop the referential actions of every reference after the first one to a given table, and db2 also drops them when the attribute is unique.
  • mssql and ibmi throw on plain-string attributes ({ id: 'INTEGER' }), which the other seven dialects accept.
  • Comments are unescaped on postgres, db2 and mssql.

Follow-up PRs

  • Fix the behaviour pinned by the TODOs above
  • Normalise AttributeToSqlOptions (table: TableOrModel, add foreignKey, drop schema)
  • Convert both methods to TypeScript and rename to attributeToSql / attributesToSql

List of Breaking Changes

None.

🤖 Generated with Claude Code

Replaces the per-dialect `attributesToSQL` suites with two dialect-agnostic
suites that cover all nine dialects, including ibmi and mssql which had no
coverage at all.

The expectations pin current behaviour exactly, so this commit changes no SQL.
Behaviour that is wrong today is pinned as-is and marked with a TODO.

`sqlite3` gains an `attributeToSQL` method, extracted from `attributesToSQL`
without changing its output, so the shared suite can cover it like every other
dialect.

`inlineErrorCause` now inspects non-error values instead of stringifying them:
mssql and ibmi return null-prototype maps from `attributesToSQL`, which threw
when the assertion message was built.

Closes sequelize#15533

Co-Authored-By: Claude Opus 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 11, 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

Copy link
Copy Markdown
Contributor Author

Superseded by #18399. Now that the agent account can push to this repo, the same commits have been reopened from sequelize/sequelize as part of stack #18403, so each PR only shows its own changes.

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