I received the following stacktrace when attempting to upgrade an instance from v0.6.0
/opt/hashview$ RACK_ENV=production rake db:upgrade
[*] Connecting to DB
rake aborted!
NoMethodError: undefined method `new' for Mysql2:Module
/opt/hashview/Rakefile:356:in `block (2 levels) in <top (required)>'
/usr/share/rvm/gems/ruby-2.4.4/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
/usr/share/rvm/gems/ruby-2.4.4/bin/ruby_executable_hooks:15:in `eval'
/usr/share/rvm/gems/ruby-2.4.4/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:upgrade
(See full trace by running task with --trace)
A brief read through the documentation showed me that this is not proper syntax for Mysql2 v0.5.2 module, which should be using Mysql2::Client.new but doing so caused several new errors that horrendously broke the application further because of subsequent (erroneous) calls to the same database connection function.
I was able to fix the issue by replacing every instance of Mysql2.new() and for some reason Mysql::new() which does not exist at all with the following line...
My question is this... why are there numerous calls to set up a new connection to the database? Why should there be multiple authentications? A far better solution would have been to create a function to return a database connection object and pass it around to the various upgrade functions rather than authenticating for each one. Since authentication to the database should happen regardless, this is far more syntactically clean and less error prone than making half a dozen Mysql2::Client.new() calls in various functions throughout the code.
Forgive my ignorance if this isn't convention or somehow illegal within Ruby, as I am not a ruby developer, but using a single function to return a database handler object would appear far more clean and reduce the chance for syntax errors when setting up the database connection. If you need to have a different db connection depending on the version of your Mysql2 gemfile, so be it, but at least abstract it away for the sake of simplicity. That's what objects were made for. 👍
I received the following stacktrace when attempting to upgrade an instance from v0.6.0
The offending line in the Rakefile is
A brief read through the documentation showed me that this is not proper syntax for Mysql2 v0.5.2 module, which should be using Mysql2::Client.new but doing so caused several new errors that horrendously broke the application further because of subsequent (erroneous) calls to the same database connection function.
I was able to fix the issue by replacing every instance of Mysql2.new() and for some reason Mysql::new() which does not exist at all with the following line...
My question is this... why are there numerous calls to set up a new connection to the database? Why should there be multiple authentications? A far better solution would have been to create a function to return a database connection object and pass it around to the various upgrade functions rather than authenticating for each one. Since authentication to the database should happen regardless, this is far more syntactically clean and less error prone than making half a dozen Mysql2::Client.new() calls in various functions throughout the code.
Forgive my ignorance if this isn't convention or somehow illegal within Ruby, as I am not a ruby developer, but using a single function to return a database handler object would appear far more clean and reduce the chance for syntax errors when setting up the database connection. If you need to have a different db connection depending on the version of your Mysql2 gemfile, so be it, but at least abstract it away for the sake of simplicity. That's what objects were made for. 👍
Submitted in PR#434