Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add queryInterface.withoutForeignKeyChecks, sequelize.destroyAll #15842

Merged
merged 12 commits into from
Apr 1, 2023

Conversation

ephys
Copy link
Member

@ephys ephys commented Mar 24, 2023

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description Of Change

I needed a way to delete all rows from all tables between tests for #15840. TRUNCATE is not a viable solution when the table is referenced by other tables (even if they're empty) in some dialects.

This PR:

  • Adds the ability to skip foreign key checks in sequelize.truncate for mysql, sqlite, mariadb via the a option: withoutForeignKeyChecks
  • Adds a new method on queryInterface: withoutForeignKeyChecks, which can be used to temporarily disable foreign keys for a given connection.
  • Adds sequelize.destroyAll which can be used as an alternative to sequelize.truncate, as it can handle foreign keys.
  • Replaces internal uses of a few deprecated APIs, like Model.tableName
  • Makes transaction.connection hard private with a getter
  • Updates setTransactionFromCls to make it synchronise the transaction and connection parameters when possible. This makes designing APIs that use these two easier. You can now specify both as long as they are compatible.
  • Replaces our test utils disableDatabaseResetForSuite & enableTruncateDatabaseForSuite with setResetMode

TODO

@ephys ephys changed the title feat: add queryInterface,withoutForeignKeyChecks, sequelize.destroyAll feat: add queryInterface.withoutForeignKeyChecks, sequelize.destroyAll Mar 25, 2023
@ephys ephys marked this pull request as ready for review March 26, 2023 14:41
@ephys ephys requested a review from a team March 26, 2023 14:44
packages/core/test/integration/support.ts Outdated Show resolved Hide resolved
packages/core/test/integration/support.ts Outdated Show resolved Hide resolved
packages/core/test/integration/model/internals.test.ts Outdated Show resolved Hide resolved
packages/core/src/transaction.ts Show resolved Hide resolved
packages/core/src/transaction.ts Show resolved Hide resolved
@ephys ephys requested a review from WikiRik April 1, 2023 12:08
@ephys ephys merged commit 3cfe672 into main Apr 1, 2023
@ephys ephys deleted the ephys/improved-truncate branch April 1, 2023 13:30
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.

None yet

2 participants