Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: use word-boundary regex for REFERENCES detection in query generators#18235

Open
Zelys-DFKH wants to merge 1 commit into
sequelize:mainsequelize/sequelize:mainfrom
Zelys-DFKH:fix/enum-references-false-positiveZelys-DFKH/sequelize:fix/enum-references-false-positiveCopy head branch name to clipboard
Open

fix: use word-boundary regex for REFERENCES detection in query generators#18235
Zelys-DFKH wants to merge 1 commit into
sequelize:mainsequelize/sequelize:mainfrom
Zelys-DFKH:fix/enum-references-false-positiveZelys-DFKH/sequelize:fix/enum-references-false-positiveCopy head branch name to clipboard

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

@Zelys-DFKH Zelys-DFKH commented Jun 5, 2026

DataTypes.ENUM('PREFERENCES') passes the .includes('REFERENCES') check in createTableQuery and changeColumnQuery because "PREFERENCES" contains "REFERENCES" as a substring. This causes the ENUM column to be emitted as a spurious FOREIGN KEY ... REFERENCES constraint instead of a column definition.

Replacing .includes('REFERENCES') with /\bREFERENCES\b/.test(...) fixes this across all eight dialect query generators (mysql, mariadb, postgres, mssql, snowflake, ibmi, oracle, db2). The db2 dialect used lodash's _.includes, which is semantically equivalent on string inputs; replaced with the same regex for consistency.

Fixes #17544

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a critical issue where ENUM values containing the word "REFERENCES" were incorrectly interpreted as foreign key constraints across all supported database systems.
  • Tests

    • Added comprehensive regression tests to ensure ENUM values containing "REFERENCES" are handled correctly without triggering foreign key misinterpretation.

…tors

DataTypes.ENUM('PREFERENCES') passes .includes('REFERENCES') in
createTableQuery and changeColumnQuery because "PREFERENCES" contains
"REFERENCES" as a substring. The ENUM column is then emitted as a
spurious FOREIGN KEY constraint instead of a column definition.

Replacing .includes('REFERENCES') with /\bREFERENCES\b/.test() across
all dialect query generators (mysql, mariadb, postgres, mssql,
snowflake, ibmi, oracle, db2).

Fixes sequelize#17544
@Zelys-DFKH Zelys-DFKH requested a review from a team as a code owner June 5, 2026 15:51
@Zelys-DFKH Zelys-DFKH requested review from WikiRik and sdepold June 5, 2026 15:51
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9126d337-19f2-479a-b98c-55b6c767fd29

📥 Commits

Reviewing files that changed from the base of the PR and between 8260c29 and 2237fff.

📒 Files selected for processing (13)
  • packages/core/test/unit/dialects/mariadb/query-generator.test.js
  • packages/core/test/unit/dialects/mysql/query-generator.test.js
  • packages/core/test/unit/dialects/postgres/query-generator.test.js
  • packages/core/test/unit/sql/change-column.test.js
  • packages/core/test/unit/sql/create-table.test.js
  • packages/db2/src/query-generator.js
  • packages/ibmi/src/query-generator.js
  • packages/mariadb/src/query-generator.js
  • packages/mssql/src/query-generator.js
  • packages/mysql/src/query-generator.js
  • packages/oracle/src/query-generator.js
  • packages/postgres/src/query-generator.js
  • packages/snowflake/src/query-generator.js

📝 Walkthrough

Walkthrough

This PR fixes a bug where ENUM column types containing the word "PREFERENCES" (or other substrings with "REFERENCES") were incorrectly parsed as foreign key constraints. The fix replaces substring matching (includes('REFERENCES')) with word-boundary regex (/\bREFERENCES\b/) across query generators in eight database dialects, ensuring only the actual SQL keyword REFERENCES triggers foreign key handling.

Changes

REFERENCES Keyword Detection Fix

Layer / File(s) Summary
Regression tests for ENUM-with-REFERENCES scenarios
packages/core/test/unit/dialects/mariadb/query-generator.test.js, packages/core/test/unit/dialects/mysql/query-generator.test.js, packages/core/test/unit/dialects/postgres/query-generator.test.js, packages/core/test/unit/sql/change-column.test.js, packages/core/test/unit/sql/create-table.test.js
New test cases verify that ENUM('PREFERENCES') and similar values are correctly emitted as column type changes via ALTER TABLE ... CHANGE rather than triggering ADD FOREIGN KEY constraints.
createTableQuery word-boundary REFERENCES detection
packages/db2/src/query-generator.js, packages/mariadb/src/query-generator.js, packages/mssql/src/query-generator.js, packages/mysql/src/query-generator.js, packages/oracle/src/query-generator.js, packages/snowflake/src/query-generator.js
createTableQuery methods updated to use /\bREFERENCES\b/ regex for keyword detection, affecting how column definitions inside PRIMARY KEY and standalone foreign key declarations are parsed and routed to constraint vs. column handling logic.
changeColumnQuery word-boundary REFERENCES detection
packages/db2/src/query-generator.js, packages/ibmi/src/query-generator.js, packages/mariadb/src/query-generator.js, packages/mssql/src/query-generator.js, packages/mysql/src/query-generator.js, packages/oracle/src/query-generator.js, packages/postgres/src/query-generator.js, packages/snowflake/src/query-generator.js
changeColumnQuery methods updated to use /\bREFERENCES\b/ regex when deciding whether to suppress DROP NOT NULL/DROP DEFAULT statements and whether to generate ADD FOREIGN KEY constraints or simple column type changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • sdepold
  • WikiRik
  • SippieCup

Poem

🐰 A word boundary saves the day,
PREFERENCES won't lead REFERENCES astray,
No false foreign keys will dare appear,
When regex guards the SQL we hold dear! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: use word-boundary regex for REFERENCES detection in query generators' clearly and specifically describes the main fix implemented across all query generators.
Linked Issues check ✅ Passed The PR directly addresses issue #17544 by replacing substring matching with word-boundary regex for REFERENCES detection, preventing false positives from ENUM values like 'PREFERENCES'.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the REFERENCES false-positive detection issue across eight dialect query generators through consistent regex updates and regression tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.4.16)
packages/db2/src/query-generator.js

File contains syntax errors that prevent linting: Line 3: Illegal use of an import declaration outside of a module; Line 4: Illegal use of an import declaration outside of a module; Line 8: Illegal use of an import declaration outside of a module; Line 12: Illegal use of an import declaration outside of a module; Line 13: Illegal use of an import declaration outside of a module; Line 14: Illegal use of an import declaration outside of a module; Line 15: Illegal use of an import declaration outside of a module; Line 16: Illegal use of an import declaration outside of a module; Line 17: Illegal use of an import declaration outside of a module; Line 18: Illegal use of an import declaration outside of a module; Line 19: Illegal use of an import declaration outside of a module; Line 20: Illegal use of an import declaration outside of a module; Line 21: Illegal use of an import declaration outside of a module; Line 22: Illegal use of an import declaration outside of a module; Line 23: Illegal use of an import declaration outside of a module; Line 24: Illegal use of an import declaration outside of a module; Line 25: Illegal use of an import declaration outside of a module; Line 26: Illegal use of an import declaration outside of a module; Line 27: Illegal use of an import declaration outside of a module; Line 28: Illegal use of an import declaration outside of a module; Line 37: Illegal use of an export declaration outside of a module

packages/ibmi/src/query-generator.js

File contains syntax errors that prevent linting: Line 3: Illegal use of an import declaration outside of a module; Line 4: Illegal use of an import declaration outside of a module; Line 8: Illegal use of an import declaration outside of a module; Line 12: Illegal use of an import declaration outside of a module; Line 13: Illegal use of an import declaration outside of a module; Line 14: Illegal use of an import declaration outside of a module; Line 15: Illegal use of an import declaration outside of a module; Line 16: Illegal use of an import declaration outside of a module; Line 17: Illegal use of an import declaration outside of a module; Line 21: Illegal use of an import declaration outside of a module; Line 22: Illegal use of an import declaration outside of a module; Line 23: Illegal use of an import declaration outside of a module; Line 24: Illegal use of an import declaration outside of a module; Line 25: Illegal use of an import declaration outside of a module; Line 31: Illegal use of an export declaration outside of a module

packages/mariadb/src/query-generator.js

File contains syntax errors that prevent linting: Line 3: Illegal use of an import declaration outside of a module; Line 7: Illegal use of an import declaration outside of a module; Line 8: Illegal use of an import declaration outside of a module; Line 9: Illegal use of an import declaration outside of a module; Line 10: Illegal use of an import declaration outside of a module; Line 11: Illegal use of an import declaration outside of a module; Line 15: Illegal use of an export declaration outside of a module

  • 5 others
🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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 and usage tips.

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.

DataType.ENUM("PREFERENCES") is parsed as "REFERENCES" so foreign key is tried to be generated.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.