Question on Jruby 1.2 and Rails 2.3.2

I believe I saw arun mention this once but I am using jruby 1.2 adn
2.3.2 with mysql (and latest AR jdbcmysql adapter). When I do a rake
db:create:all. I only get the test and production dbs to be created
… the development one doesn’t. Has anyone done any investigation
into this ? (I’m game to start investigating but wanted to find out
if anything’s been done)

Jay


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Jay McGaffigan wrote:

I believe I saw arun mention this once but I am using jruby 1.2 adn
2.3.2 with mysql (and latest AR jdbcmysql adapter). When I do a rake
db:create:all. I only get the test and production dbs to be created
… the development one doesn’t. Has anyone done any investigation
into this ? (I’m game to start investigating but wanted to find out
if anything’s been done)

Weird, I had not heard about that. Do you have a link to Arun’s mention?

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hey, knock yourself out :slight_smile: It’s probably not a hard one to track down.

Jay McGaffigan wrote:

Jay McGaffigan wrote:

http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

http://jira.codehaus.org/browse/JRUBY-3502

He even filed a bug.

As I said I’m happy to help investigate :slight_smile:

Jay

On Sat, Apr 25, 2009 at 4:51 PM, Charles Oliver N.
[email protected] wrote:

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Well I’m making progress. But it’s weird.

When running rake db:create:all it appears that the jdbc adapter stuff
isn’t being loaded until after the create:all stuff has started to be
processed.

So in the jdbc.rake file we alias the AR create_database method. But
this aliasing isn’t happening until we are halfway through the
create_database call in the origianl database.rake on the
ActiveRecord::establish_connection call. Which is weird.

What this means is that in a db:create:all call the first entry in the
config hash (which contains the contents of the database.yml file)
always fails (in our case it just happens to be the name of the
development hash settings).

I’m just not sure yet why this stuff isn’t loaded sooner. I’ll play
with more things tonight to see if I can find out why it’s not being
loaded sooner.

Jay

On Sun, Apr 26, 2009 at 12:54 AM, Charles Oliver N.
[email protected] wrote:

Jay

into this ? (I’m game to start investigating but wanted to find out


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Jay McGaffigan wrote:

What this means is that in a db:create:all call the first entry in the
config hash (which contains the contents of the database.yml file)
always fails (in our case it just happens to be the name of the
development hash settings).

I’m just not sure yet why this stuff isn’t loaded sooner. I’ll play
with more things tonight to see if I can find out why it’s not being
loaded sooner.

Loaded sooner, or you could investigate if it’s a Hash default proc or
something and in that proc we’re supposed to be reinserting everything.
Shot in the dark…but it sounds like you’re on the right track.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Jay McGaffigan wrote:

However that doesn’t work as db:create:all in 2.3.2 doesn’t load environment.rb

Ah-ha. How about boot.rb? Or something boot.rb loads? Maybe plugin init
or something?

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

So after much digging it appears that the JDBC adapter stuff just
isn’t loading until too late in a db:create call.

The Kenai wiki points to putting the following code into your
environment.rb call
if RUBY_PLATFORM =~ /java/
require ‘rubygems’
gem ‘activerecord-jdbc-adapter’
require ‘jdbc_adapter’
end

However that doesn’t work as db:create:all in 2.3.2 doesn’t load
environment.rb

My solution?

For now I put it in the database.yml file in a ruby tag:

<%
if RUBY_PLATFORM =~ /java/
require ‘rubygems’
gem ‘activerecord-jdbc-adapter’
require ‘jdbc_adapter’
end
%>

This force loads the JDBC adapter causing the proper aliasing to happen.

This problem exists for:
rake db:create:all
and rake db:create

From tracing through the code it does look like the problem exists for
any jdbc supported database.

It would be nicer to have it implicitly load sooner.

I am off to test and make sure this “workaround” doesn’t negatively
affect other rake tasks
Jay

On Mon, Apr 27, 2009 at 10:26 PM, Charles Oliver N.
[email protected] wrote:


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I feel like we’re doing it wrong…there must be a correct way according
to Rails folks to get our logic bootstrapped for purposes of db
migration. Obviously environment.rb isn’t it and boot.rb doesn’t seem to
be either.

Jay McGaffigan wrote:

Jay McGaffigan wrote:
http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

boot.rb seems to work too.
I’ve always shied away from boot.rb but it makes sense that it would
be good to put it there.

Think this belongs on the wiki?

Jay

On Tue, Apr 28, 2009 at 8:53 PM, Charles Oliver N.
[email protected] wrote:


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

We can probably make that case; they’ve included other fixes of ours, so
if there’s a patch to be submitted I bet they’d accept it.

Jay McGaffigan wrote:

I feel like we’re doing it wrong…there must be a correct way according to

Jay

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

From looking at the code tho Rails call to establish_connection causes
rails/AR to go looking for connection adapters.

On a rake db:create that call doesn’t happen until halfway through the
create_database call… it’s at this point that the JDBC AR adapter
stuff does it’s magic of aliasing the create_database call.

It would seem to me a BETTER solution would be for the rails team to
accept a patch to make create_database (in the database.rake file) be
able to discover the connection adapters sooner.

I mean at this point doesn’t the JDBC stuff deserve “first class”
citizenship in there?

:slight_smile:

Jay

On Tue, Apr 28, 2009 at 9:48 PM, Charles Oliver N.
[email protected] wrote:

Think this belongs on the wiki?


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email