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

rake db:create failing when I use mysql2_makara adapter #264

Open
akashp90 opened this issue Aug 10, 2020 · 2 comments
Open

rake db:create failing when I use mysql2_makara adapter #264

akashp90 opened this issue Aug 10, 2020 · 2 comments

Comments

@akashp90
Copy link

akashp90 commented Aug 10, 2020

Hello,
I am a newbie to rails and do not know the intricacies of how everything works.
I have spent more than I want to admit trying to figure out if something is wrong with my database.yml config.

Here is my database.yml

adapter_default: &adapter_default
  adapter : mysql2_makara
  encoding: utf8

default: &default
  <<: *adapter_default
  database: <%= Rails.application.secrets.database_name %>
  host    : <%= Rails.application.secrets.database_host %>
  username: <%= Rails.application.secrets.database_user %>
  password: <%= Rails.application.secrets.database_password %>
  port    : <%= Rails.application.secrets.database_port %>
  makara:
    sticky: true
    connections:
      - role: master
        name: primary
        host    : <%= Rails.application.secrets.database_host %>
        username: <%= Rails.application.secrets.database_user %>
        password: <%= Rails.application.secrets.database_password %>
        port    : <%= Rails.application.secrets.database_port %>
      - name: replica
        host    : <%= Rails.application.secrets.database_host %>
        database: <%= Rails.application.secrets.replica_database_name %>
        username: <%= Rails.application.secrets.database_user %>
        password: <%= Rails.application.secrets.database_password %>
        port    : <%= Rails.application.secrets.database_port %>

development:
  <<: *default

test:
  <<: *default

staging:
  <<: *default

production:
  <<: *default
  pool: <%= Rails.application.secrets.database_connection_pool_size || 5 %>

read_replica:
  <<: *adapter_default
  database: <%= Rails.application.secrets.replica_database_name %>
  host    : <%= Rails.application.secrets.database_host %>
  username: <%= Rails.application.secrets.database_user %>
  password: <%= Rails.application.secrets.database_password %>
  port    : <%= Rails.application.secrets.database_port %>

When I run rake db:create, it errors. Here is the stack trace

Unknown database 'test_db'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/mysql2_adapter.rb:23:in `rescue in mysql2_connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/mysql2_adapter.rb:10:in `mysql2_connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/active_record/connection_adapters/mysql2_makara_adapter.rb:39:in `active_record_connection_for'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/active_record/connection_adapters/makara_abstract_adapter.rb:201:in `connection_for'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/makara/proxy.rb:126:in `block in graceful_connection_for'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/active_record/connection_adapters/makara_abstract_adapter.rb:38:in `handle'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/makara/proxy.rb:125:in `graceful_connection_for'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/makara/proxy.rb:280:in `block (2 levels) in instantiate_connections'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/makara/pool.rb:39:in `add'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/makara/proxy.rb:279:in `block in instantiate_connections'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/makara/proxy.rb:278:in `each'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/makara/proxy.rb:278:in `instantiate_connections'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/makara/proxy.rb:57:in `initialize'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/active_record/connection_adapters/makara_abstract_adapter.rb:140:in `initialize'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/active_record/connection_adapters/mysql2_makara_adapter.rb:9:in `new'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/makara-0.4.1/lib/active_record/connection_adapters/mysql2_makara_adapter.rb:9:in `mysql2_makara_connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_handling.rb:87:in `connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/tasks/mysql_database_tasks.rb:8:in `connection'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/tasks/mysql_database_tasks.rb:16:in `create'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/tasks/database_tasks.rb:93:in `create'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/tasks/database_tasks.rb:278:in `block in each_current_configuration'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/tasks/database_tasks.rb:277:in `each'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/tasks/database_tasks.rb:277:in `each_current_configuration'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/task.rb:273:in `block in execute'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/task.rb:273:in `each'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/task.rb:273:in `execute'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/task.rb:214:in `block in invoke_with_call_chain'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/task.rb:194:in `invoke_with_call_chain'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/task.rb:183:in `invoke'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:160:in `invoke_task'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:116:in `each'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:116:in `block in top_level'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:125:in `run_with_threads'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:110:in `top_level'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:83:in `block in run'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:80:in `run'
/Users/akashparvatikar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
/Users/akashparvatikar/.rbenv/versions/2.3.1/bin/rake:23:in `load'
/Users/akashparvatikar/.rbenv/versions/2.3.1/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"mysql2_makara", "encoding"=>"utf8", "database"=>"some_database", "host"=>"127.0.0.1", "username"=>"root", "password"=>nil, "port"=>3306, "makara"=>{"sticky"=>true, "connections"=>[{"role"=>"master", "name"=>"primary", "host"=>"127.0.0.1", "username"=>"root", "password"=>nil, "port"=>3306}, {"name"=>"replica", "host"=>"127.0.0.1", "database"=>"test_db", "username"=>"root", "password"=>nil, "port"=>3306}]}}

However, everything works find if I create the db myself using the mysql console.
Also, if I do not use the mysql2_makara adapter, the db is created without any issue.
Hence, this leads me to believe rake db:create doesn't work with the mysql2_makara adapter
Btw, I am using rails 4.2.6

@Axxiss
Copy link

Axxiss commented Sep 8, 2020

Yes, we have the same problem. We ended up using an ENV var for using one adapter of the other. That way we can create the DB in CI and test with a as close to production setup as possible.

Something similar to what's described here #245

@akashp90
Copy link
Author

akashp90 commented Sep 8, 2020

@Axxiss, we wanted to go with a similar approach, but we ended up using Octopus instead of Makara.

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

No branches or pull requests

2 participants