Add :force option to create_enum#29
Merged
bibendi merged 4 commits intobibendi:masterfrom Aug 21, 2020
cloudtruth:add-force-option
Merged
Add :force option to create_enum#29bibendi merged 4 commits intobibendi:masterfrom cloudtruth:add-force-option
bibendi merged 4 commits intobibendi:masterfrom
cloudtruth:add-force-option
Conversation
…les. Without this change, `db:setup` will fail by default when run with a database that already contains the enum.
Owner
|
Released 1.4.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
This PR adds a new
:forceoption tocreate_enumthat's intended to follow whatcreate_tabledoes in ActiveRecord. Notably, this work fixes #22 and allows the rakedb:setuptask to succeed. However, existing schema.rb files need to be updated to take advantage of the new option. Runningrake db:schema:dumpshould be enough to update existingcreate_enumcalls. Newly run migrations will have:forceset to:cascadeby default.Related tickets
#22 db:setup fails with ActiveRecord::StatementInvalid: PG::DuplicateObject
What's inside
There is a new option to
create_enum::force.When set to any truthy value,
create_enumwill be preceded by adrop_enumcall. This call will do anIF EXISTScheck, but will not cascade default unless the:forcevalue is set to:cascade. As far as I can tell, this mirrors what ActiveRecord does forcreate_table.Additionally, I've updated the schema dumper to set
force: :cascadefor any new entries to the schema.rb. I believe this matches how ActiveRecord handles newly created tables and, as such, matches what many developers expect. But, I'm not an ActiveRecord internals expert so I may have misinterpreted some of the existing code.I should note that I couldn't figure out when
CommandRecorderis invoked, so I didn't modify it. Please provide guidance there if changes are necessary.Checklist:
I've added tests for code that already had tests. There were no tests for the schema dumper and I didn't know how to get started with that, so there are no new tests for this functionality either.
I don't think any documentation is warranted, but please let me know if you'd like something.