Well, I agree that that's kind of silly. When you have a very large app,
it can take quite a bit of time to load the environment... And, when
we're talking about just creating a db, I don't see why we need the
environment. Then again, I never use db:create... I just use mysqladmin.
I think loading the environment with db:create and db:drop is
unnecessary. I've run into scenarios where a plugin does some
initialization based on the database and raises exceptions if there is
no database (ultrasphinx and acts_as_ferret are two that come to
mind).
Whenever I set up an app on a new machine, and I have a plugin that
expects a database installed, I have to script/dbconsole to create the
database. It's not world-ending, but it is annoying.
Also, it seems, based on the 2 threads I linked in the original post,
that this behaviour was introduced in rails 2.1 -- but I haven't
confirmed that myself.
In my case (replying to Andrew Bloom's question), I was automatically
defining helper methods like "admin?", "student?", etc, based on data
in the roles table, to save typing "current_user.has_role?(:admin)"
etc... my code was smart enough to not fail if the roles table was
missing (so that at least the migrations creating the roles table
wouldn't fail), but I wasn't checking for the presence of the entire
database. rake db:create fails before creating the database, because
it loads my application, which expects a database!
I agree that it's not a huge issue, but you know, I think rails could
do with some tidying up before the next million new features are
added. For someone relatively new to rails like myself, all these
small issues add up and bite one or two days out of every week of
work. I don't mean to criticise anyone that works on rails, your work
is hugely appreciated, and I realise I should be submitting patches
myself if I want things to improve (once I get my head around the
rails code). But I feel like I have been battling against the
framework far more than necessary. Hopefully rails has reached a high
enough level of maturity, feature-wise, that bug-fixes will be given
priority over new features.
rails code). But I feel like I have been battling against the
framework far more than necessary.
As I see it it's an education problem - at least for the examples mentioned.
Plugins like better_nested_set are clearly framework level plugins (extending ActiveRecord features). As such they should not make any assumptions about a database being present and it should be possible to implement it like that I guess. *)
Also, plugin models that act_as_nested_set cause this problem only if they are loaded during plugin loading time. Avoid that the model is loaded when the plugin's init.rb is loaded and the problem will go away. Again, to me this seems, even if obscure and hard to teach, rather like an education problem (because the plugin has been designed the wrong way) than a problem with rake tasks requiring the environment (which generally makes sense).
*) (There are application level plugins out there for which it *might* make sense to make assumptions about the database but they also can't because Rails still has no concept of application level plugins ... but that's a different story
+1 on this comment, and I don't think this should be considered a
plugin design flaw.
This thread is like deja vu of the database.yml vs. environment config thread.
I still believe that any *external* dependencies or resources
(databases, gems) should get special treatment. In other words, if
there is a dependency which is external to the app, any rails
provisions for managing it should not be dependent on the app
initializing first. Otherwise, it's a chicken and egg problem.
That's why db:create should not depend on the app initializing, and
also (shameless plug) why I'd prefer the GemInstaller (which has
standalone as well as integrated invocation options) over config.gems
for managing gems, including the Rails gem(s) itself