Closed TheNotary closed 8 years ago
I fucking hate rails and it's bullshit handling of environment variables. This bit me in the ass at work as well.
There isn't really a way to do this at the moment as the scheme is hardcoded here. You could change that in your copy while we try and figure out a good way to handle this.
It would definitely be useful for other apps as well, like sqlalchemy and it's driver handling.
You could also set your own DATABASE_URL and then link the databases. I believe the plugin will handle that and not override your env var.
@josegonzalez not sure that ranting about Rails is very useful :wink: The problem here is the MySQL adapter, if you use PG then there is no problem :grin:
So, as you said, one way is to just change mysql
by mysql2
in the DATABASE_URL
variable. You can do this after linking. We could then document this in the README, like you can see it’s been done here: https://devcenter.heroku.com/articles/cleardb#provisioning-the-add-on
Another option is to allow the PLUGIN_SCHEME
variable to be defined by the user as we’ve done before for images and versions. So when linking we could do something like this: PLUGIN_SCHEME=mysql2 dokku mysql:link db app
Rails is the one that sets the adapter automatically based on the scheme coming in...
Well the Heroku buildpack also writes a specific database.yml
from DATABASE_URL
: https://github.com/heroku/heroku-buildpack-ruby/blob/master/lib/language_pack/ruby.rb#L651 (and use the postgresqsl
adapter when the scheme is postgres
)
Probably we should make a PR upstream for it to do the right thing for mysql?
Well the problem is that it seems for mysql, there are really two distinct adapters and one might want to use mysql
while another will want to use mysql2
. And I’m pretty sure Rails still auto-select the adapter when DATABASE_URL
exists (even without the Heroku buildpack).
When looking at https://www.ruby-toolbox.com/categories/SQL_Database_Adapters, it seems the mysql
gem is not much used nowadays but I don’t know.
Thanks for the great workaround ideas! Patching that line of code and installing from a fork did the trick perfectly I think (we're sorting out our first dokku machine, atm).
On Flink's statement about mysql vs mysql2, it appears that mysql reached a deprecated status sometime in 2013 and is also no longer maintained. I'm not 100% sure what the differing philosophies of the two gems are, but given that mysql
has been unmaintained for years I have a hunch that forcing the plugin to default to mysql2 wouldn't cramp the style of too many rubiests.
It really should be fixed upstream in the buildpack.
I've come across this recently, and I think changing it in the buildpack will only fix it for Active Record versions prior to 4.1: https://github.com/heroku/heroku-buildpack-ruby/blob/37c0375cf664630919a7b2916f128b77e2888c3e/lib/language_pack/ruby.rb#L662
Otherwise it lets Active Record merge DATABASE_URL and database.yml: http://edgeguides.rubyonrails.org/configuring.html#configuring-a-database so it'd require patching in both places to try and detect the presence of the mysql2 gem. I think it's better to allow it to be configurable in the mysql plugin.
Mind creating a PR for this, @petewest ?
I'm getting the following error message:
I'm under the impression dokku will ignore database.yml and use it's configurations specified over the commandline, so I can't just switch the adaptor to
mysql2
. I'm reading that themysql
adaptor only has strings and integers whereas themysql2
adaptor is production ready. Is there a way to use mysql2 at this time?