padrino/padrino-framework — Issue #784: ActiveRecord rake file should not prompt the user to log in as root if database authentication fails
Author: jfarmer
Created: 2012-02-11 03:01:09+00:00
State: open

Hello,

I'm just starting to use Padrino and my ORM combination of choice is ActiveRecord + mysql2.

When I first ran padrino rake ar:create I received an error about an uninitialized constant Mysql at line 65 of the following file, so I took a look.

https://github.com/padrino/padrino-framework/blob/master/padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb#L65-82

This code seems wrong to me for the following reasons:

1. It doesn't work with Mysql2. In that case the exception will be a Mysql2::Error. Moreover, Mysql2 doesn't have constants defined for the various MySQL errno's, so the next line (#66) would fail, too.
2. None of the other adapters in Padrino for ActiveRecord special-case this exception
3. None of the other Padrino ORM code special-cases this exception for MySQL
4. It tightens the coupling between Padrino and the underlying adapter vs. relying on the ORM to handle the adapter
5. It assumes I have access to the root user of my database
6. It assumes that I use my root account to create databases in my database
7. It assumes that I want to grant all privileges to the user I specify in my database configuration
8. It assumes that I'm granting privileges to a user coming in from localhost

I think Padrino should get out of this business and leave the database account management in the database layer. The right behavior is to just throw the error and tell the user what's going on.

I'm submitting a patch and pull request for this in a second.

Cheers,
Jesse