diff options
author | Grey Baker <greysteil@gmail.com> | 2015-12-17 09:19:43 +0000 |
---|---|---|
committer | Grey Baker <greysteil@gmail.com> | 2015-12-17 09:25:50 +0000 |
commit | d927f35bf04a93b5fd7aaa5ab8081f6bad070746 (patch) | |
tree | 179ec6e11e6ac5081fe6628e932b8d4bfd4742e9 /activerecord/lib | |
parent | c4f8ce53b1f9af9585aeec9bbb0c66fc9c48ec1b (diff) | |
download | rails-d927f35bf04a93b5fd7aaa5ab8081f6bad070746.tar.gz rails-d927f35bf04a93b5fd7aaa5ab8081f6bad070746.tar.bz2 rails-d927f35bf04a93b5fd7aaa5ab8081f6bad070746.zip |
Support passing the schema name prefix to `conenction.indexes`
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.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index a48d64f7bd..98a3ce6782 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -169,15 +169,18 @@ module ActiveRecord # 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 |