customink / secondbase

Seamless second database integration for Rails.
MIT License
220 stars 31 forks source link

Connection url not parsed for mysqldump #61

Closed nickcoyne closed 2 months ago

nickcoyne commented 5 years ago

With a Rails 5.2 app that uses config.active_record.schema_format = :sql, when I run rails db:second_base:migrate I get a mysqldump error. It appears that it is not correctly parsing the user/password from my connection url.

$ rails db:second_base:migrate
mysqldump: Got error: 1045: Access denied for user 'nick'@'localhost' (using password: NO) when trying to connect
rails aborted!
failed to execute: `mysqldump`
Please check the output above for any errors and make sure that `mysqldump` is installed in your PATH and has proper permissions.

/Users/nick/.rbenv/versions/2.5.3/gemsets/teded-5-2-gemset/gems/activerecord-5.2.2/lib/active_record/tasks/mysql_database_tasks.rb:105:in`run_cmd'

Inspecting the connection shows:

"{\"adapter\"=>\"mysql2\", \"encoding\"=>\"utf8\", \"reconnect\"=>false, \"pool\"=>1, \"url\"=>\"mysql2://root@localhost:3306/myapp_stats_development\", \"variables\"=>{\"sql_mode\"=>\"TRADITIONAL\"}}"

vs. this on the main database connection:

"{\"adapter\"=>\"mysql2\", \"encoding\"=>\"utf8mb4\", \"reconnect\"=>false, \"variables\"=>{\"sql_mode\"=>\"TRADITIONAL\"}, \"username\"=>\"root\", \"port\"=>3306, \"database\"=>\"myapp_development\", \"host\"=>\"localhost\"}"

I'm using the same format connection url for both databases.

metaskills commented 5 years ago

Are you using the latest version? Also, we advocate that you run db:migrate and let SecondBase run db:second_base:migrate for you. This is so it can setup the ENV vars and all the patches to allow the second task to run correctly. Details here: https://github.com/customink/secondbase#database-tasks

Interested in hearing the results.

nickcoyne commented 5 years ago

Unfortunately exactly the same result just running db:migrate. I'm using the latest 2.1.6.

Also I tried a fresh Rails 5.2 app and got the same result...

$ rails db:create
Created database 'test2nd_development'
Created database 'test2nd_test'
Created database 'test2nd_second_development'
Created database 'test2nd_second_test'

$ rails db:migrate
mysqldump: Got error: 1045: Access denied for user 'nick'@'localhost' (using password: NO) when trying to connect
rails aborted!
failed to execute: `mysqldump`
Please check the output above for any errors and make sure that `mysqldump` is installed in your PATH and has proper permissions.

/Users/nick/Projects/codevader/test2nd/bin/rails:9:in `<top (required)>'
/Users/nick/Projects/codevader/test2nd/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:structure:dump
metaskills commented 5 years ago

Thanks, it sounds like we need to add Rails v5.2 to our Appraisals (https://github.com/customink/secondbase/blob/master/Appraisals) and do a few more freedom patches. I won't have time for a while so in the meantime, open to PRs if you feel up to it.

nickcoyne commented 5 years ago

It seems to be an issue on Rails 5.1 too, I just tried with a fresh application.