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

Migrations will raise an exception if there are multiple column defin… #33029

Merged
merged 1 commit into from Jun 4, 2018

Conversation

@fedxgibson
Copy link
Contributor

@fedxgibson fedxgibson commented May 31, 2018

Migrations raise exception when defining already defined column.

TableDefinition#column checks if there is already a column defined with the same name. In this case it will raise an exception.

@rails-bot
Copy link

@rails-bot rails-bot commented May 31, 2018

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@fedxgibson fedxgibson force-pushed the fedxgibson:raise_with_duplicate_columns branch May 31, 2018
@a7madM
a7madM approved these changes Jun 1, 2018
…itions (same name).
@fedxgibson fedxgibson force-pushed the fedxgibson:raise_with_duplicate_columns branch to 7ef9849 Jun 1, 2018
@eileencodes eileencodes merged commit c4c8e35 into rails:master Jun 4, 2018
2 checks passed
2 checks passed
codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@eileencodes
Copy link
Member

@eileencodes eileencodes commented Jun 4, 2018

Thanks for fixing this! 🎉

@fedxgibson
Copy link
Contributor Author

@fedxgibson fedxgibson commented Jun 7, 2018

Glad to help! :)

NickLaMuro added a commit to NickLaMuro/manageiq-schema that referenced this pull request Dec 11, 2020
In Rails 6, a "bug fix" was added to avoid creating duplicate columns:

  rails/rails#33029

This wasn't very well described what this was fixing, but this seems to
be the issue it was fixing:

  rails/rails#33024

However, the problem we had as a result was this error with our specs
when running migrations:

  1) ExpandDialogFieldDefaultValueSize#down with empty tables
     Failure/Error: super

     StandardError:
       An error has occurred, this and all later migrations canceled:

       you can't define an already defined column 'miq_server_id'.
     # ./db/migrate/20160328204930_remove_miq_server_product_update_join_table.rb:21:in `block in down'
     # ./db/migrate/20160328204930_remove_miq_server_product_update_join_table.rb:20:in `down'
     # ./lib/manageiq/schema/migrate_with_cleared_schema_cache.rb:6:in `block in migrate'
     # ./lib/manageiq/schema/migrate_with_cleared_schema_cache.rb:18:in `clearing_caches'
     # ./lib/manageiq/schema/migrate_with_cleared_schema_cache.rb:5:in `migrate'
     # ./spec/support/migration_helper.rb:109:in `block in migrate_to'
     # ./spec/support/migration_helper.rb:99:in `suppress_migration_messages'
     # ./spec/support/migration_helper.rb:105:in `migrate_to'
     # ./spec/support/migration_helper.rb:42:in `prepare_migrate'
     # ./spec/support/migration_helper.rb:8:in `block (2 levels) in migration_context'
     # ------------------
     # --- Caused by: ---
     # ArgumentError:
     #   you can't define an already defined column 'miq_server_id'.
     #   ./db/migrate/20160328204930_remove_miq_server_product_update_join_table.rb:21:in `block in down'

And was expressed by this issue to rails:

  rails/rails#35448

In which the answer was "fix your migrations".

I don't really buy that answer, as that is why they have versioned
migration classes in the first place, but for now, this is the fix
available to us and seems to allow most of the specs to pass.

On top of that, we can't use `create_join_table` as we previously did
since we now can't overwrite default columns and choose what column
type we want to use since the only thing we can provide with the kwargs
is the `:column_options`, but we will always get the foriegn_key columns
as `integer`.

That said, this is a down migration, so probably not worth investing
trying to get this changed upstream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.