Hello,

We're using Rails on an Oracle database. If we define an index like the following, we end up with problems during the "db:schema:dump" rake target.

 add_index "emcolumn", ["upper(name)"], :name => "ind_emcolumn_uname"

The created schema.rb file contains:

 add_index "emcolumn", ["sys_nc00013$"], :name => "ind_emcolumn_uname"

Well, we are aware we can use "config.active_record.schema_format = :sql" to fall back to a SQL file containing only table definition statements. However it would be nice if the Oracle adapter would understand such constructs. A possible solution for this problem is attached as patch against Rails 1.2 RC1.

I'm quite sure it's not perfect yet. Maybe someone can pick up the idea and improve it to make it ready to go into the official sources.

Best Regards,
Andreas Gungl

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Index: vendor/rails/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
===================================================================
--- vendor/rails/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb	(revision 2316)
+++ vendor/rails/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb	(working copy)
@@ -289,10 +289,11 @@
 
         def indexes(table_name, name = nil) #:nodoc:
           result = select_all(<<-SQL, name)
-            SELECT lower(i.index_name) as index_name, i.uniqueness, lower(c.column_name) as column_name
-              FROM user_indexes i, user_ind_columns c
+            SELECT lower(i.index_name) as index_name, i.uniqueness, lower(c.column_name) as column_name, e.column_expression
+              FROM user_indexes i, user_ind_columns c, user_ind_expressions e
              WHERE i.table_name = '#{table_name.to_s.upcase}'
                AND c.index_name = i.index_name
+               AND i.index_name = e.index_name (+)
                AND i.index_name NOT IN (SELECT uc.index_name FROM user_constraints uc WHERE uc.constraint_type = 'P')
               ORDER BY i.index_name, c.column_position
           SQL
@@ -306,7 +307,13 @@
               current_index = row['index_name']
             end
 
-            indexes.last.columns << row['column_name']
+            column_name = row['column_name']
+            if column_name =~ /^sys_/
+              column_name = row['column_expression']
+              column_name.downcase!
+              column_name.gsub!(/\"/, '')
+            end
+            indexes.last.columns << column_name
           end
 
           indexes

Reply via email to