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

[Bug] Migration bug after Rails 5.2 #489

Closed
NickLaMuro opened this issue Mar 17, 2020 · 6 comments · Fixed by #491
Closed

[Bug] Migration bug after Rails 5.2 #489

NickLaMuro opened this issue Mar 17, 2020 · 6 comments · Fixed by #491
Labels

Comments

@NickLaMuro
Copy link
Member

NickLaMuro commented Mar 17, 2020

So while working on #469 and was asked to change a column in the database, I ended up re-running migrations entirely by doing the following:

$ RAILS_ENV=development bundle exec rake db:environment:set db:drop db:create db:migrate

...

== 20150730043503 CreateBatchTables: migrating ================================
-- create_table(:batch_jobs, {})
   -> 0.0027s
   -- create_table(:batch_entries, {})
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

Index name 'index_batch_entries_on_batch_job_id' on table 'batch_entries' already exists
activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:1160:in `add_index_options'
activerecord-5.2.4.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:465:in `add_index'
activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:315:in `block in create_table'
activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:314:in `each'
activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:314:in `create_table'
activerecord-5.2.4.1/lib/active_record/migration.rb:871:in `block in method_missing'
activerecord-5.2.4.1/lib/active_record/migration.rb:840:in `block in say_with_time'
activerecord-5.2.4.1/lib/active_record/migration.rb:840:in `say_with_time'
activerecord-5.2.4.1/lib/active_record/migration.rb:860:in `method_missing'
activerecord-5.2.4.1/lib/active_record/migration/compatibility.rb:34:in `create_table'
miq_bot/db/migrate/20150730043503_create_batch_tables.rb:8:in `change'

The error returned was remedied by doing one of the following:

  1. Commenting/deleting out this line:

  1. Changing the migration to inherit from ActiveRecord::Migration[4.2] instead of 5.1.

Option 2 is probably the more "correct" approach, but does end up changing the db/schema.rb, and was technically written for Rails 4.0, and you can't use that version with the versioned migration classes.

ArgumentError:  Unknown migration version "4.0"; expected one of "4.2", "5.0", "5.1", "5.2"

So "asking the audience" on what we think is the best approach to fix this, and I can put together a PR. If "Option 2", we probably should fix all of the migrations so they are based off the closest Rails version available, so that will be a much larger change.

@Fryguy
Copy link
Member

Fryguy commented Mar 18, 2020

I'm thinking Option 2.

@Fryguy Fryguy added the bug label Mar 18, 2020
@NickLaMuro
Copy link
Member Author

Okay, I might try looking into this today then. Option 1 was the one line change shown above, so the other one will take a bit more work to do, but should be manageable.

@NickLaMuro
Copy link
Member Author

@miq-bot assign @NickLaMuro

@miq-bot
Copy link
Member

miq-bot commented Mar 18, 2020

@NickLaMuro 'NickLaMuro' is an invalid assignee, ignoring...

@NickLaMuro
Copy link
Member Author

FINE! BE THAT WAY!!!1!

😤

@NickLaMuro
Copy link
Member Author

Alright, opened up a fix in #491

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants