JRuby on Rails: Integration Plugin Goes 1.0

Posted by Nick Sieger Fri, 16 Mar 2007 16:55:00 GMT

On the heels of my last post, Robert announced the 1.0 release of Rails Integration, the bits that allow JRuby on Rails to be run out of a Java web archive (war). If you have any interest at all in trying out JRuby on Rails, do yourself a favor and try out the integration bits. Even though this is 1.0, we’re still moving rapidly and would appreciate any and all feedback. (And Robert is doing his best to keep up with changes in core.)

Related to this, Stuart Halloway recently announced his J plugin which is a drop-in collection of Rake tasks that bridge the inherent differences between Rails running on C Ruby vs. JRuby. We still have some work to do in some areas, such as database driver configuration, test database bootstrapping and launching unit tests. For example, instead of the big, ugly, database-specific case statement that’s in Rails’ databases.rake today:

desc "Recreate the test databases from the development structure"
task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
  abcs = ActiveRecord::Base.configurations
  case abcs["test"]["adapter"]
    when "mysql"
      ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')

").each do |table|
    when "postgresql"
      ENV['PGHOST']     = abcs["test"]["host"] if abcs["test"]["host"]
      ENV['PGPORT']     = abcs["test"]["port"].to_s if abcs["test"]["port"]
      ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
      `psql -U "#{abcs["test"]["username"]}" -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
    when "sqlite", "sqlite3"
      dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
      `#{abcs["test"]["adapter"]} #{dbfile} < db/#{RAILS_ENV}_structure.sql`
    when "sqlserver"
      `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\#{RAILS_ENV}_structure.sql`
    when "oci", "oracle"

").each do |ddl|
    when "firebird"
      db_string = firebird_db_string(abcs["test"])
      sh "isql -i db/#{RAILS_ENV}_structure.sql #{db_string}"
      raise "Task not supported by '#{abcs["test"]["adapter"]}'"

we can use migrations to create the test database:

desc "Recreate the test databases from migrations"
task :migrate_test_db do
  ActiveRecord::Schema.verbose = t.application.options.trace

Over time, I hope to see all these efforts coalesce and make the Rails developer experience virtually identical on either interpreter. What would be most excellent is to eventually push some of these improvements back to the Rails core.

Tags ,  | 2 comments | no trackbacks


  1. Avatar atmos said about 1 hour later:

    Note that most people never execute that code since they use the pure ruby schema, they use the :clone task.

    The task, fugly as it is, does have its place if people are working on dbs with procedures, triggers, or custom sequences. While you’d hope this stuff would be in the migrations, I have a feeling that people add that sorta stuff manually because rails doesn’t give them an easy way to do it(beyond execute).

  2. Avatar Nick said about 2 hours later:

    Point taken. Although there is similar ugly code in db:structure:dump and db:test:purge, the last of which is in the standard task sequence when running tests.

    My guess is that stuff is a hold-over from pre-migrations Rails that will hopefully be deprecated and axed in the future.


Use the following link to trackback from your own site: