Permalink
Browse files

fixes bug with PostgreSQLAdapter#indexes

When the search path has multiple schemas, spaces were not being stripped
from the schema names after the first.
  • Loading branch information...
1 parent e3ba072 commit 58f2fbc2ad6e19284fdd7bd0d690dabf3e736a9d @sskirby sskirby committed Nov 4, 2011
@@ -754,7 +754,6 @@ def extract_schema_and_table(name)
# Returns an array of indexes for the given table.
def indexes(table_name, name = nil)
- schemas = schema_search_path.split(/,/).map { |p| quote(p) }.join(',')
result = query(<<-SQL, name)
SELECT distinct i.relname, d.indisunique, d.indkey, t.oid
FROM pg_class t
@@ -763,7 +762,7 @@ def indexes(table_name, name = nil)
WHERE i.relkind = 'i'
AND d.indisprimary = 'f'
AND t.relname = '#{table_name}'
- AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname IN (#{schemas}) )
+ AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false)) )
ORDER BY i.relname
SQL
@@ -164,6 +164,10 @@ def test_dump_indexes_for_schema_two
do_dump_index_tests_for_schema(SCHEMA2_NAME, INDEX_A_COLUMN, INDEX_B_COLUMN_S2)
end
+ def test_dump_indexes_for_schema_multiple_schemas_in_search_path
+ do_dump_index_tests_for_schema("public, #{SCHEMA_NAME}", INDEX_A_COLUMN, INDEX_B_COLUMN_S1)
+ end
+
def test_with_uppercase_index_name
ActiveRecord::Base.connection.execute "CREATE INDEX \"things_Index\" ON #{SCHEMA_NAME}.things (name)"
assert_nothing_raised { ActiveRecord::Base.connection.remove_index! "things", "#{SCHEMA_NAME}.things_Index"}

0 comments on commit 58f2fbc

Please sign in to comment.