Repository navigation
fix(core): skip removing foreign keys in dropAllTables when dropping with cascade - #18497
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
… with cascade DROP TABLE ... CASCADE already drops the foreign keys that reference the table, so looking up and removing each table's foreign keys first is redundant for dialects that drop with cascade (postgres, oracle, snowflake). On Oracle, the foreign key lookup is a slow dictionary query. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Uses tables with cyclic foreign keys, so the test fails if the foreign keys are not removed before the tables are dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
85015e0 to
183f1fc
Compare
…tions Co-Authored-By: Claude Opus 5.5 <[email protected]>
* origin/main: (54 commits) fix: use bind parameters in the Oracle catalog queries (sequelize#18498) meta: update mysql docker tag to v8.4.13 (sequelize#18577) meta: update dependency eslint-plugin-jsdoc to v65.4.0 (sequelize#18575) meta: update dependency node to v24.22.1 (sequelize#18574) meta: update dependency @oclif/core to ^5.1.9 (sequelize#18573) fix(core): skip removing foreign keys in dropAllTables when dropping with cascade (sequelize#18497) fix(core): drop each model only once in Sequelize#drop (sequelize#18572) fix(postgres): drop the enum types of a model when its table is dropped (sequelize#18554) fix(core): avoid lodash omit in the Model constructor (sequelize#18556) meta(core): support async functions in expectPerDialect (sequelize#18569) meta: update dependency ibm_db to ^4.1.0 (sequelize#18571) fix(core): make rejectInvalidOptions iterate supportable options and accept undefined (sequelize#18557) fix(core): respect the omitNull option of calls and models, fix query generator typings (sequelize#18565) meta(core): convert unit/model tests to TypeScript (sequelize#18564) meta(core): convert unit/instance tests to TypeScript (sequelize#18563) meta: update sequelize AUTHORS (sequelize#18549) feat(mssql): add useUnicodeStrings dialect option (sequelize#18548) meta: retry image pulls in the database start scripts (sequelize#18340) meta(core): follow-ups to the isModelStatic cache from sequelize#18234 (sequelize#18559) meta: update dependency uuid to v14 (sequelize#18544) ... # Conflicts: # packages/postgres/src/query-interface.js
* origin/main: (26 commits) fix: use bind parameters in the Oracle catalog queries (sequelize#18498) meta: update mysql docker tag to v8.4.13 (sequelize#18577) meta: update dependency eslint-plugin-jsdoc to v65.4.0 (sequelize#18575) meta: update dependency node to v24.22.1 (sequelize#18574) meta: update dependency @oclif/core to ^5.1.9 (sequelize#18573) fix(core): skip removing foreign keys in dropAllTables when dropping with cascade (sequelize#18497) fix(core): drop each model only once in Sequelize#drop (sequelize#18572) fix(postgres): drop the enum types of a model when its table is dropped (sequelize#18554) fix(core): avoid lodash omit in the Model constructor (sequelize#18556) meta(core): support async functions in expectPerDialect (sequelize#18569) meta: update dependency ibm_db to ^4.1.0 (sequelize#18571) fix(core): make rejectInvalidOptions iterate supportable options and accept undefined (sequelize#18557) fix(core): respect the omitNull option of calls and models, fix query generator typings (sequelize#18565) meta(core): convert unit/model tests to TypeScript (sequelize#18564) meta(core): convert unit/instance tests to TypeScript (sequelize#18563) meta: update sequelize AUTHORS (sequelize#18549) feat(mssql): add useUnicodeStrings dialect option (sequelize#18548) meta: retry image pulls in the database start scripts (sequelize#18340) meta(core): follow-ups to the isModelStatic cache from sequelize#18234 (sequelize#18559) meta: update dependency uuid to v14 (sequelize#18544) ... # Conflicts: # packages/core/src/abstract-dialect/query-generator.js # packages/core/src/abstract-dialect/query-interface-typescript.ts # packages/core/test/unit/model/bulk-create.test.js # packages/core/test/unit/sql/insert.test.js
Description of Changes
queryInterface.dropAllTables()looks up and removes every table's foreign keys before dropping the tables. For dialects that drop withcascade(Postgres, Oracle and Snowflake, wherecascadeis enabled by default), this is redundant:DROP TABLE ... CASCADE(CASCADE CONSTRAINTSon Oracle) already drops the foreign keys that reference the dropped table.This PR skips the foreign-key pass when the tables are dropped with
cascade. Dialects without cascade, and calls with an explicitcascade: false, keep the current behaviour.The integration test suite calls
dropAllTablesafter almost every test, and on Oracle the foreign-key lookup is a slow dictionary query (see #18498). Locally, runningtest/integration/associations/**onmainspends 6.5 s of its 26 s on Postgres in the foreign-key lookups of thedatabase resethook, all of which this PR removes. On Oracle 23 the same run issued 610 fewer foreign-key lookups, saving ~15 s of SQL time. The existingdropAllTablesintegration tests (foreign keys, schemas,skip) pass on Postgres and Oracle.The foreign-key pass no longer runs by default on these dialects, so this PR adds a test that calls
dropAllTables({ cascade: false })on tables with cyclic foreign keys, which only succeeds if the foreign keys are removed first. It fails on Postgres when the pass is disabled. On Oracle that test can't fail, because Oracle'sdropTableQueryalways usesCASCADE CONSTRAINTS. The cyclic test also runs with the default options on every dialect. That covers the new path on Postgres and Oracle, and gives the other dialects their first cyclic-FK coverage of the foreign-key pass.CI, after rebasing onto main (6995f15). Median duration of the "Integration Tests" step, compared with 30 recent runs on the same main:
dropTable.cascade, so they still run the pass.Related: #18572 fixes
Sequelize#dropdropping every model two or three times, which also affectssync({ force: true }).List of Breaking Changes
None.
🤖 Generated with Claude Code
Summary by CodeRabbit