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
:force
option tocreate_enum
that's intended to follow whatcreate_table
does in ActiveRecord. Notably, this work fixes #22 and allows the rakedb:setup
task to succeed. However, existing schema.rb files need to be updated to take advantage of the new option. Runningrake db:schema:dump
should be enough to update existingcreate_enum
calls. Newly run migrations will have:force
set to:cascade
by 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_enum
will be preceded by adrop_enum
call. This call will do anIF EXISTS
check, but will not cascade default unless the:force
value 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: :cascade
for 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
CommandRecorder
is 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.