Rake db:migrate failing against oracle

Hello All –

I am using jruby 1.6.7.2 with rails 3.2.11 to create a brown bag for
several other developers. I cannot get the migration to work to save my
life…

In my database yaml file I have the following:

development:
adapter: jdbc
driver: oracle.jdbc.driver.OracleDriver
url: jdbc:oracle:thin:@localhost:1521:xe
username: brownbag
password: brownbag
pool: 500

When I run:

rake db:create --trace
** Invoke db:create (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:create

when I run:

C:\temp\brownbag\my_workout>rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
Table schema_migrations does not exist
arjdbc/jdbc/RubyJdbcConnection.java:126:in columns' c:/temp/brownbag/gem_home/gems/activerecord-jdbc-adapter-1.2.5/lib/arjdbc/oracle/adapter.rb:358:inora_columns’
c:/temp/brownbag/gem_home/gems/activerecord-3.2.11/lib/active_record …

If I switch my databse.yml file to the original slite3 that rails auto
generates all is fine.

If I place the following in irb:


require ‘rubygems’
require ‘activerecord-jdbc-adapter’
require ‘active_record’
require ‘active_record/version’

a= ActiveRecord::Base.establish_connection(
:adapter => ‘jdbc’,
:driver => ‘oracle.jdbc.driver.OracleDriver’,
:url => ‘jdbc:oracle:thin:@localhost:1521:xe’,
:username=>‘brownbag’,
:password=>‘brownbag’
)

c = a.connection
ct = “CREATE TABLE example (id INT, data VARCHAR(100) )”
d = c.exec_query(ct)

The table is created as expected!

Help!

Thanks,

Cris

Chris -

I don’t know the reason, but here’s a possible workaround:

The error reported says that the schema_migrations table does not exist.
What if you couuld create that table manually? In SQLite, the commands
executed appear to be:

CREATE TABLE “schema_migrations” (“version” varchar(255) NOT NULL);
CREATE UNIQUE INDEX “unique_schema_migrations” ON “schema_migrations”
(“version”);

I wonder if you do the equivalent in Oracle, if the rest of it will
succeed.

  • Keith

Keith,

Thanks for your reply. I will try it tomorrow.

I suspect it will work because my coding partner had me try it. He did
not get the table (schema_migrations) quite right so it failed but it
failed complaining about the malformed table.

Obviously, in a brown bag scenario, such a solution will not work. It
would utterly destroy the Rails magic mojo…

Cris

On Thu, Jan 31, 2013 at 5:15 PM, Cris S. [email protected]
wrote:

adapter: jdbc
driver: oracle.jdbc.driver.OracleDriver

Ewww. Luckily, I no longer have to deal with Rails and Oracle – my
experience with that combination was not pleasant – but you might
want to try using https://github.com/rsim/oracle-enhanced as your
adapter.

HTH,

Hassan S. ------------------------ [email protected]

twitter: @hassan

Chris -

A couple of other things that may help, though to be honest I’m stabbing
in the dark

  1. In my article about using Oracle with JRuby and Rails
    (http://www.bbs-software.com/blog/2013/01/09/using-oracle-in-jruby-and-rails/),
    I had the following line in my database.yml, which was slightly
    different from yours (I don’t know if they’re both correct, or if even
    I’m wrong, but I’m pretty sure it worked for me):

driver: oracle.jdbc.OracleDriver

  1. There have been some problems with the activerecord-jdbc-adapter gem.
    As far as I know, the last version that worked correctly with other gems
    was 1.2.2.1. It’s probably a lot more complex than that, but I don’t
    know the details. You might want to try setting that version in your
    Gemfile and see if it helps.
  • Keith

Keith R. Bennett

Maybe a role problem on Oracle Db…??? Try a Dba user…
El 01/02/2013 02:16, “Cris S.” [email protected] escribi:

Have you tried running rake db:schema:load or rake db:create first?
Those tasks should create the migration schema tables.

On Feb 1, 2013, at 9:38 AM, Manuel R. wrote:




c:/temp/brownbag/gem_home/gems/activerecord-jdbc-adapter-1.2.5/lib/arjdbc/oracle/adapter.rb:358:in

require ‘rubygems’
)
Thanks,


Felix Gilcher
Geschftsfhrer

m. +49 172 840 88 28

asquera GmbH
Ohlauer Strae 43
D-10999 Berlin

AG Charlottenburg, HRB 140808 B
Geschftsfhrung: Felix Gilcher, Florian G.

Update:

Tried 1.2.2.1 with and w/o ‘driver’ in 'driver:
‘oracle.jdbc.driver.OracleDriver’

The result was the same in each case…

rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
Table schema_migrations does not exist
arjdbc/jdbc/RubyJdbcConnection.java:121:in columns' c:/temp/brownbag/gem_home/gems/activerecord-jdbc-adapter-1.2.2.1/lib/arjdbc/oracle/adapter.rb:348:inora_columns’

I tried the enhanced driver and it worked! For anyone else following my
footsteps, for clarity, here is what I did:

Gemfile add:
#gem ‘activerecord-jdbc-adapter’, ‘1.2.2.1’
gem ‘activerecord-oracle_enhanced-adapter’, ‘~> 1.4.0’

database.yml add:

development:
adapter: oracle_enhanced
host: localhost
port: 1521
database: xe
username: brownbag
password: brownbag
#development:

adapter: jdbc

driver: oracle.jdbc.OracleDriver

url: jdbc:oracle:thin:@localhost:1521:xe

username: brownbag

password: brownbag

rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
== CreateExercises: migrating

– create_table(:exercises)
-> 1.0470s
== CreateExercises: migrated (1.0470s)

** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:dump

YAY!!

Now if I switch back to the other adapter and make use of the fact that
it got my schema_migrations in there for me it dose ‘work’.

I will be using the enhanced driver.

Thank you Keith and Hassan!

BTW I am currently using the activerecord-jdbc-adapter against oracle in
our production app. It tookwaaay too much effort to make it work there.
Effort that would destroy a brown bag. As in, “Now manually patch the
driver like so…”

I am surprised such a fundamental driver has such issues with such a
large database.

Thanks all,

Cris