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

Fix a bug with initialize schema_migrations table #23307

Merged
merged 1 commit into from Jan 28, 2016

Conversation

Projects
None yet
4 participants
@mgrachev
Contributor

mgrachev commented Jan 28, 2016

Performing a command bundle exec rake db:drop db:create db:schema:load --trace I get the following error:

-- initialize_schema_migrations_table()
   -> 0.0081s
rake aborted!
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR:  syntax error at or near "{"
LINE 1: ...NSERT INTO "schema_migrations" (version) VALUES (#{v}), (#{v...
                                                             ^
: INSERT INTO "schema_migrations" (version) VALUES (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (
#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v}), (#{v})
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:133:in `async_exec'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:133:in `block in execu
te'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:528:in `block in log'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activesupport/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:522:in `log'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:132:in `execute'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:995:in `assume_migrated_up
to_version'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/schema.rb:52:in `define'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/schema.rb:44:in `define'
/Users/mgrachev/mm/db/schema.rb:14:in `<top (required)>'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activesupport/lib/active_support/dependencies.rb:296:in `load'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activesupport/lib/active_support/dependencies.rb:296:in `block in load'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activesupport/lib/active_support/dependencies.rb:268:in `load_dependency'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activesupport/lib/active_support/dependencies.rb:296:in `load'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/tasks/database_tasks.rb:216:in `load_schema'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/tasks/database_tasks.rb:246:in `block in load_schema_current'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/tasks/database_tasks.rb:286:in `block in each_current_configuration'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/tasks/database_tasks.rb:285:in `each'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/tasks/database_tasks.rb:285:in `each_current_configuration'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/tasks/database_tasks.rb:245:in `load_schema_current'
/Users/mgrachev/mm/vendor/bundle/bundler/gems/rails-9864bcee8cfd/activerecord/lib/active_record/railties/databases.rake:260:in `block (3 levels) in <top (required)>'
/Users/mgrachev/mm/vendor/bundle/gems/rake-10.5.0/lib/rake/task.rb:240:in `call'
/Users/mgrachev/mm/vendor/bundle/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/Users/mgrachev/mm/vendor/bundle/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/Users/mgrachev/mm/vendor/bundle/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
@rails-bot

This comment has been minimized.

rails-bot commented Jan 28, 2016

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (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.

Please see the contribution instructions for more information.

@eileencodes

This comment has been minimized.

Member

eileencodes commented Jan 28, 2016

Hey @mgrachev thanks for the PR! Can you just update the commit message to explain the bug like you did in your comment? That way someone doesn't have to come back to Github to figure out what the bug was. Thanks!

@mgrachev

This comment has been minimized.

Contributor

mgrachev commented Jan 28, 2016

Done

@eileencodes

View changes

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb Outdated
@@ -992,7 +992,7 @@ def assume_migrated_upto_version(version, migrations_paths)
if (duplicate = inserting.detect {|v| inserting.count(v) > 1})
raise "Duplicate migration #{duplicate}. Please renumber your migrations to resolve the conflict."
end
execute "INSERT INTO #{sm_table} (version) VALUES #{inserting.map {|v| '(#{v})'}.join(', ') }"
execute "INSERT INTO #{sm_table} (version) VALUES #{inserting.map {|v| "(#{v})"}.join(', ') }"

This comment has been minimized.

@eileencodes

eileencodes Jan 28, 2016

Member

It's early here and maybe the coffee hasn't settled in yet but looking at a previous line I think we need to still quote the value.

ActiveRecord::SchemaMigration.order('version').pluck(:version).map {|v| "('#{v}')" }.join(', ')

Does the migration work if you add single quotes inside like this:
execute "INSERT INTO #{sm_table} (version) VALUES #{inserting.map {|v| "('#{v}')"}.join(', ') }"

This comment has been minimized.

@mgrachev

mgrachev Jan 28, 2016

Contributor

This variant also works

Fix a bug with initialize schema_migrations table
This line causes an error when executing the command: `rails db:drop db:create db:schema:load`

ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR:  syntax error at or near "{"
LINE 1: ...NSERT INTO "schema_migrations" (version) VALUES (#{v}), (#{v...
@mgrachev

This comment has been minimized.

Contributor

mgrachev commented Jan 28, 2016

Updated

britg added a commit to britg/rails that referenced this pull request Jan 28, 2016

Regression test for rails#23307
This exercises `assume_migrated_upto_version` in `activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb`

`db:drop db:create db:schema:load` and triggers the error mentioned in rails#23307

@britg britg referenced this pull request Jan 28, 2016

Closed

Regression test for #23307 #23312

eileencodes added a commit that referenced this pull request Jan 28, 2016

Merge pull request #23307 from mgrachev/fix-schema-migrations
Fix a bug with initialize schema_migrations table

@eileencodes eileencodes merged commit 2637fb7 into rails:master Jan 28, 2016

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@eileencodes

This comment has been minimized.

Member

eileencodes commented Jan 28, 2016

Thanks!

@mgrachev mgrachev deleted the mgrachev:fix-schema-migrations branch Jan 28, 2016

britg added a commit to britg/rails that referenced this pull request Jan 28, 2016

Regression test for rails#23307
This exercises `assume_migrated_upto_version` in `activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb`

`db:drop db:create db:schema:load` and triggers the error mentioned in rails#23307
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment