-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Transactions can be turned off per Migration #9507
Transactions can be turned off per Migration #9507
Conversation
@rafaelfranca @carlosantoniodasilva what do you think? |
# | ||
# If the database adapter supports ddl transactions, all migrations will | ||
# automatically be wrapped in a transaction. There are queries that you | ||
# can't execute inside a transaction. For these situations you can turn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... inside a transaction though, and for...
wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I'm not sure if I like |
From the wording I would go with
|
Does it need to be an option? |
My first implementation did not use an option but a method call like If you don't like |
# end | ||
# | ||
# Remeber that you can still open your own transactions, even if you | ||
# are in a Migration with <tt>self.with_transaction = false</tt>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's one extra space at the beginning of these lines. Also Migration
can be downcased I think.
Seems good @senny, I'm just not sure about the naming yet. |
The cleanup commit a85625d broke the test-case. The schema was no longer modified so there was no way to check that the rollback actually happened.
# end | ||
# end | ||
# | ||
# Remeber that you can still open your own transactions, even if you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo Remeber
=> Remember
Closes rails#9483. There are SQL Queries that can't run inside a transaction. Since the Migrator used to wrap all Migrations inside a transaction there was no way to run these queries within a migration. This patch adds `self.disable_ddl_transaction!` to the migration to turn transactions off when necessary.
@rafaelfranca @carlosantoniodasilva I pushed an updated and rebased version:
|
|
||
cattr_accessor :verbose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just a glitch in the diff, you see, it was removed on the top: https://github.com/rails/rails/pull/9507/files#L1L368
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh. Right.
Transactions can be turned off per Migration
👍 |
👍 Thanks Senny |
@senny Our team came across this when trying to reduce memory consumption on a data migration for a larger table. It helped us out a lot, thank you for adding this! We were curious why the name |
@PhilCoggins this name was chosen after some brainstorming. It expressed best what most people relate with the wrapping transaction. While it does not disable "all transactions", the wrapping transaction can contain non-ddl statements. You can still have transactions inside your migration when you use |
Closes #9483.
There are SQL Queries that can't run inside a transaction. Since
the Migrator used to wrap all Migrations inside a transaction there
was no way to run these queries within a migration.
This patch adds
self.with_transaction = false
to the migration toturn transactions off when necessary.