Merge pull request #22623 from greysteil/support-passing-schema-name-to-indexes
Support passing the schema name prefix to `conenction.indexes`
This commit is contained in:
commit
da6713fd03
@ -1,3 +1,10 @@
|
||||
* Support passing the schema name as a prefix to table name in
|
||||
`ConnectionAdapters::SchemaStatements#indexes`. Previously the prefix would
|
||||
be considered a full part of the index name, and only the schema in the
|
||||
current search path would be considered.
|
||||
|
||||
*Grey Baker*
|
||||
|
||||
* Ignore index name in `index_exists?` and `remove_index` when not passed a
|
||||
name to check for.
|
||||
|
||||
|
@ -169,15 +169,18 @@ def index_name_exists?(table_name, index_name, default)
|
||||
|
||||
# Returns an array of indexes for the given table.
|
||||
def indexes(table_name, name = nil)
|
||||
result = query(<<-SQL, 'SCHEMA')
|
||||
SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid
|
||||
FROM pg_class t
|
||||
INNER JOIN pg_index d ON t.oid = d.indrelid
|
||||
INNER JOIN pg_class i ON d.indexrelid = i.oid
|
||||
WHERE i.relkind = 'i'
|
||||
AND d.indisprimary = 'f'
|
||||
AND t.relname = '#{table_name}'
|
||||
AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false)) )
|
||||
table = Utils.extract_schema_qualified_name(table_name.to_s)
|
||||
|
||||
result = query(<<-SQL, 'SCHEMA')
|
||||
SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid
|
||||
FROM pg_class t
|
||||
INNER JOIN pg_index d ON t.oid = d.indrelid
|
||||
INNER JOIN pg_class i ON d.indexrelid = i.oid
|
||||
LEFT JOIN pg_namespace n ON n.oid = i.relnamespace
|
||||
WHERE i.relkind = 'i'
|
||||
AND d.indisprimary = 'f'
|
||||
AND t.relname = '#{table.identifier}'
|
||||
AND n.nspname = #{table.schema ? "'#{table.schema}'" : 'ANY (current_schemas(false))'}
|
||||
ORDER BY i.relname
|
||||
SQL
|
||||
|
||||
|
@ -321,6 +321,11 @@ 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, INDEX_D_COLUMN, INDEX_E_COLUMN)
|
||||
end
|
||||
|
||||
def test_dump_indexes_for_table_with_scheme_specified_in_name
|
||||
indexes = @connection.indexes("#{SCHEMA_NAME}.#{TABLE_NAME}")
|
||||
assert_equal 4, indexes.size
|
||||
end
|
||||
|
||||
def test_with_uppercase_index_name
|
||||
@connection.execute "CREATE INDEX \"things_Index\" ON #{SCHEMA_NAME}.things (name)"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user