Skip to content

Loading…

Fix to dump function indexes correctly #161

Merged
merged 2 commits into from

3 participants

@cosine

Function indexes do not dump correctly in lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb. They end up with quotes around the entire function string, which makes Oracle look for a really odd column name instead of realize it is working with a function index.

@yahonda
Collaborator

This pull request passes all oracle-enhanced unit tests with Rails 3.2.3, 3.1.4 and 2.3.14. It looks good.

@yahonda yahonda merged commit d6b920c into rsim:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
2 lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb
@@ -117,7 +117,7 @@ def structure_dump_indexes(table_name) #:nodoc:
else
index_type = options
end
- quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ")
+ quoted_column_names = column_names.map { |e| quote_column_name_or_expression(e) }.join(", ")
"CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{quoted_column_names})"
end
end
View
12 spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb
@@ -181,6 +181,18 @@ class ::TestPost < ActiveRecord::Base
dump.should =~ /CREATE INDEX "?IX_TEST_POSTS_FOO\"? ON "?TEST_POSTS"? \("?FOO"?\)/i
dump.should_not =~ /CREATE UNIQUE INDEX "?UK_TEST_POSTS_/i
end
+
+ it "should dump multi-value and function value indexes" do
+ ActiveRecord::Base.connection.add_index(:test_posts, [:foo, :foo_id], :name => :ix_test_posts_foo_foo_id)
+
+ @conn.execute <<-SQL
+ CREATE INDEX "IX_TEST_POSTS_FUNCTION" ON "TEST_POSTS" (TO_CHAR(LENGTH("FOO"))||"FOO")
+ SQL
+
+ dump = ActiveRecord::Base.connection.structure_dump
+ dump.should =~ /CREATE INDEX "?IX_TEST_POSTS_FOO_FOO_ID\"? ON "?TEST_POSTS"? \("?FOO"?, "?FOO_ID"?\)/i
+ dump.should =~ /CREATE INDEX "?IX_TEST_POSTS_FUNCTION\"? ON "?TEST_POSTS"? \(TO_CHAR\(LENGTH\("?FOO"?\)\)\|\|"?FOO"?\)/i
+ end
end
describe "temporary tables" do
after(:all) do
Something went wrong with that request. Please try again.