Skip to content

Conversation

@netroy
Copy link

@netroy netroy commented Apr 29, 2025

typeorm#7922 added the code to disable/enable foreign key checks for sqlite when running migrations individually, but is missing the code do so when the migrations are run via connection.runMigrations().
This change ensures a consistent behavior between all the code paths.

Copy link

@despairblue despairblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok, but I'm wondering about one thing.

If this.transaction is all wouldn't we commit outside of a transaction?

First this runs:

if (this.transaction === "all" && !queryRunner.isTransactionActive) {
await queryRunner.beforeMigration()
await queryRunner.startTransaction()
transactionStartedByUs = true
}

Then let's assume there is only one migration.
This is skipped, because queryRunner.isTransactionActive is true:

if (migration.transaction && !queryRunner.isTransactionActive) {
await queryRunner.beforeMigration()
await queryRunner.startTransaction()
transactionStartedByUs = true
}

Then we commit, since transactionStartedByUs is true:

if (migration.transaction && transactionStartedByUs) {
await queryRunner.commitTransaction()
}

Then this runs, because transactionStartedByUs is still true:

if (this.transaction === "all" && transactionStartedByUs) {
await queryRunner.commitTransaction()
}

So we're

  1. starting transaction
  2. don't start another one
  3. commit the transaction
  4. try to commit again

Or am I missing something?

@netroy netroy closed this Aug 5, 2025
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.

3 participants