Skip to content

Conversation

@brandur
Copy link
Contributor

@brandur brandur commented Dec 21, 2025

We had a problem reported recently wherein a user who was executing
migrations in tight contention with each other hit a problem where
because a transaction is only in operation right around the immediate
SQL of each migration, it's easily possible to get all the side effects
of a transaction without actually adding/removing any versions. In the
event of such a failure, the database is left in an irreconcilable
state. Neither migrating up or down can fix the problem, with the only
option being manual intervention.

Here, when running without an outer transaction, run version insertion
or deletion immediately so that it happens immediately inside the inner
transaction, thereby preventing this problem.

All MigrateTx test exercise was completely stripped out so I added a
couple basic tests back in so that this code has some coverage.

@brandur brandur force-pushed the brandur-single-tx branch 2 times, most recently from 3c53e9b to e0e457b Compare December 21, 2025 14:49
@brandur brandur requested a review from bgentry December 21, 2025 14:53
@bertpersyn-nxh
Copy link

Thanks

Comment on lines 424 to 425
// When operating with an outer transaction, add/remove all versions at once
// so we can save a few database operations.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only removing, not adding, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good catch. Corrected this comment.

We had a problem reported recently wherein a user who was executing
migrations in tight contention with each other hit a problem where
because a transaction is only in operation right around the immediate
SQL of each migration, it's easily possible to get all the side effects
of a transaction without actually adding/removing any versions. In the
event of such a failure, the database is left in an irreconcilable
state. Neither migrating up or down can fix the problem, with the only
option being manual intervention.

Here, when running without an outer transaction, run version insertion
or deletion immediately so that it happens immediately inside the inner
transaction, thereby preventing this problem.

All `MigrateTx` test exercise was completely stripped out so I added a
couple basic tests back in so that this code has some coverage.
@brandur
Copy link
Contributor Author

brandur commented Dec 22, 2025

Thanks!

@brandur brandur merged commit ff4bb63 into master Dec 22, 2025
14 checks passed
@brandur brandur deleted the brandur-single-tx branch December 22, 2025 20:55
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.

4 participants