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

Update #6791 "AR::Migrator.bulk_migration option" #11530

Closed
wants to merge 2 commits into from

Conversation

Empact
Copy link
Contributor

@Empact Empact commented Jul 21, 2013

This update #6791 and integrates it with the disable_ddl_transaction! option that was added since the PR was first opened.

Could probably use some additional testing to handle the interplay between these two features.

@tamird
Copy link
Contributor

tamird commented Sep 24, 2014

@Empact could you rebase this?

@Empact Empact force-pushed the bulk_migration branch 2 times, most recently from 040456d to e2859bd Compare September 25, 2014 04:24
@Empact
Copy link
Contributor Author

Empact commented Sep 25, 2014

Done - incidentally I noticed some more defunct ivars, a total of 4, so I removed them in a separate commit.

@tamird
Copy link
Contributor

tamird commented Sep 25, 2014

@Empact sorry about the back and forth - looks like this is already supported unless explicitly disabled by the migration?

@Empact
Copy link
Contributor Author

Empact commented Sep 28, 2014

@tamird No this is not currently supported - currently each migration is run in a transaction, unless disable_ddl_transaction! is called, but if you run several migrations, there's no way to cleanly roll back them all if a single migration fails.

This feature is useful for deploys in that you can ensure that no database changes occur if any of your migrations fail. This would mean you could have a truly clean rollback to the pre-deploy state, rather than have some data changes persist even if you roll back your code changes in response to a migration failure.

@tamird
Copy link
Contributor

tamird commented Sep 29, 2014

Hmm. I think I disagree with this change - it feels natural to me to expect each migration to be atomic but extending atomicity to the group of transactions that happen to run in the same invocation feels surprising and even sloppy to me. 👍 on the drive-by cleanups you found though, would be good to open a separate PR for them so that this discussion doesn't prevent their inclusion.

@Empact
Copy link
Contributor Author

Empact commented Sep 29, 2014

Ok closing based on your comments here, and @rafaelfranca's comment on #6791

Extracted the ivars commit to #17092

@Empact Empact closed this Sep 29, 2014
@matthewd
Copy link
Member

This sounds quite desirable to me; if half the migrations run and then one fails, neither the previously-deployed nor currently-checked-out code can be expected to work with the resulting database. In sufficiently merge-ful conditions, there may in fact be no intermediate commit that had this set of migrations.

However, I think a migration that's explicitly opted out of a transaction should still have its wishes honoured. If we can arrange that, without too badly contorting things, then I'm 👍 to merge (and, personally, use) this option.

@Empact
Copy link
Contributor Author

Empact commented Sep 29, 2014

@matthewd I may take the time to extract it as a gem. Will post back here if I do.

@matthewd
Copy link
Member

@Empact if you can fix the behaviour for migrations that have explicitly disabled the surrounding transaction, I'll merge it: it sounds desirable to me, and while that opinion doesn't seem universal, I haven't seen any objections to it being a non-default option.

@Empact Empact reopened this Sep 29, 2014
@Empact
Copy link
Contributor Author

Empact commented Sep 29, 2014

@matthewd Does this line do what you're thinking?:
bulk_migrating = bulk_migration && runnable.none?(&:disable_ddl_transaction)

@matthewd
Copy link
Member

I guess I was imagining that the "ideal" interpretation would be to still cluster transaction-able migrations together. So:

begin
migration_1
migration_2
commit
migration_3 (disable_ddl_transaction)
begin
migration_4
migration_5
commit

But yeah, fallback to the current behaviour sounds quite defensible... and much simpler to implement. 😄

@Empact
Copy link
Contributor Author

Empact commented Sep 29, 2014

We could print a message when a ddl-disabled migration leads to the run being run individually.

@bogdan
Copy link
Contributor

bogdan commented Feb 24, 2015

+1, @Empact thanks for renewing this one

bogdan and others added 2 commits October 23, 2015 17:59
Enables running migration under same DDL transaction
if supported by database
@pingortle
Copy link

Does anyone have plans to follow up on this? If not, perhaps we should close the issue.

@Empact Empact closed this Jul 10, 2019
@Empact Empact deleted the bulk_migration branch July 10, 2019 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants