On Wed, May 6, 2009 at 9:28 AM, Norman Smith
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> My app is using JRuby on Rails and Oracle. I have a join table that has
> not ID column. When I create the table via db:migrate, no Oracle
> Sequence is set up for it. Later when I populate the table with data, I
> get an error that the sequence for the table doesn''t exist. The
> db:migrate error is:
>
> == UpdatePackagesValues: migrating ===================================>
rake aborted!
> An error has occurred, all later migrations canceled:
>
> ActiveRecord::ActiveRecordError: ORA-02289: sequence does not exist
> : select packages_values_seq.nextval id from dual
>
> I am using ActiveRecord-JDBC (0.5) and activerecord-jdbc-adapter (0.8)
> gems for accessing the database. The current 0.9.1 adapter has several
> problems that I can''t work around. This feels like bug in
> activerecord-jdbc-adapter (0.8) and I can work around it by manually
> creating the Oracle Sequence object.
>
> Also related is the fact that the Oracle Sequence Objects default to
> starting at 10000. Is this an Oracle thing or can it be configured in
> the adapter? I think I can get around this issue for now by manually
> deleting and recreating the Sequence Objects before any data is loaded
> into the database.
I found similar issues with the OracleEnhanced driver. I fixed things
up like this:
module ActiveRecord
module ConnectionAdapters
class OracleEnhancedAdapter
def create_table(name, options = {}) #:nodoc:
super(name, options)
seq_name = options[:sequence_name] || "#{name}_seq"
execute "CREATE SEQUENCE #{seq_name} START WITH 1 INCREMENT BY
1 NOCACHE ORDER NOCYCLE" unless options[:id] == false
end
end
module SchemaStatements
def add_index(table_name, column_name, options = {})
column_names = Array(column_name)
index_name = index_name(table_name, :column => column_names)
if Hash === options # legacy support, since this param was a string
# add support for Oracle bitmap indexes
index_type = options[:unique] ? "UNIQUE" : options[:bitmap]
? "BITMAP" : ""
index_name = options[:name] || index_name
else
index_type = options
end
quoted_column_names = column_names.map { |e|
quote_column_name(e) }.join(", ")
execute "CREATE #{index_type} INDEX
#{quote_column_name(index_name)} ON #{quote_table_name(table_name)}
(#{quoted_column_names})"
end
end
end
end
--
Greg Donald
http://destiney.com/