Add activerecord-jdbcpostgresql-adapter gem (v 0.8.2) to gems used by NetBeans JRuby 1.1.2 install. This will also upgrade the activerecord-jdbc-adaptor gem to 0.8.2
Create new Rails project (Rails 2.1.0 IIRC), any server. Select JDBC, PostgreSQL, enter username, no password, on db page.
Modify database.yml to use jdbcpostgres adapter
Make sure the database required by the project does not yet exist.
Run rake db:create
It will run w/o visible errors
Check to see if database was created – it won't be.
I debugged this extensively and what it resolved to in my case was this:
In jdbc.rake, around line 33, the code tries to create the database with this line:
ActiveRecord::Base.connection.create_database(config['database'])
It was throwing a no such method exception because the JdbcAdapter instance referenced by ActiveRecord::Base.connection did not define a create_database method.
I also noted that jdbc_postgres.rb does not define this method. When I added a definition of create_database to this file, the rake task succeeded as expected.
rake db:drop has similar issues as I suspect do some of the other jdbc adapters.
def create_database(name, options = {}) #:nodoc:
execute "CREATE DATABASE #{name} ENCODING='#{options[:charset] || 'utf8'}'"
end
def drop_database(name) #:nodoc:
execute "DROP DATABASE #{name}"
end
The encoding is probably not correct (should use encoding field from database.yml, I'm not sure this does that correctly). There may also be other options required. PostgreSQL does not appear to support the "IF EXISTS / IF NOT EXISTS" capability that MySQL does, so these commands (create/drop) should only be executed if it is known that the action is required.