Skip to content

Commit 39abd78

Browse files
committed
[postgres] remove #indexes, rely on version from schema_statements
1 parent 4b6fd5f commit 39abd78

File tree

1 file changed

+0
-55
lines changed

1 file changed

+0
-55
lines changed

lib/arjdbc/postgresql/adapter.rb

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -522,61 +522,6 @@ def truncate(table_name, name = nil)
522522
execute "TRUNCATE TABLE #{quote_table_name(table_name)}", name
523523
end
524524

525-
# Returns an array of indexes for the given table.
526-
def indexes(table_name, name = nil)
527-
# FIXME: AR version => table = Utils.extract_schema_qualified_name(table_name.to_s)
528-
schema, table = extract_schema_and_table(table_name.to_s)
529-
530-
result = query(<<-SQL, 'SCHEMA')
531-
SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid,
532-
pg_catalog.obj_description(i.oid, 'pg_class') AS comment,
533-
(SELECT COUNT(*) FROM pg_opclass o
534-
JOIN (SELECT unnest(string_to_array(d.indclass::text, ' '))::int oid) c
535-
ON o.oid = c.oid WHERE o.opcdefault = 'f')
536-
FROM pg_class t
537-
INNER JOIN pg_index d ON t.oid = d.indrelid
538-
INNER JOIN pg_class i ON d.indexrelid = i.oid
539-
LEFT JOIN pg_namespace n ON n.oid = i.relnamespace
540-
WHERE i.relkind = 'i'
541-
AND d.indisprimary = 'f'
542-
AND t.relname = '#{table}'
543-
AND n.nspname = #{schema ? "'#{schema}'" : 'ANY (current_schemas(false))'}
544-
ORDER BY i.relname
545-
SQL
546-
547-
result.map do |row|
548-
index_name = row[0]
549-
# FIXME: These values [1,2] are returned in a different format than AR expects, maybe we could update it on the Java side to be more accurate
550-
unique = row[1].is_a?(String) ? row[1] == 't' : row[1] # JDBC gets us a boolean
551-
indkey = row[2].is_a?(Java::OrgPostgresqlUtil::PGobject) ? row[2].value : row[2]
552-
indkey = indkey.split(" ").map(&:to_i)
553-
inddef = row[3]
554-
oid = row[4]
555-
comment = row[5]
556-
opclass = row[6]
557-
558-
using, expressions, where = inddef.scan(/ USING (\w+?) \((.+?)\)(?: WHERE (.+))?\z/).flatten
559-
560-
if indkey.include?(0) || opclass > 0
561-
columns = expressions
562-
else
563-
columns = Hash[query(<<-SQL.strip_heredoc, "SCHEMA")].values_at(*indkey).compact
564-
SELECT a.attnum, a.attname
565-
FROM pg_attribute a
566-
WHERE a.attrelid = #{oid}
567-
AND a.attnum IN (#{indkey.join(",")})
568-
SQL
569-
570-
# add info on sort order for columns (only desc order is explicitly specified, asc is the default)
571-
orders = Hash[
572-
expressions.scan(/(\w+) DESC/).flatten.map { |order_column| [order_column, :desc] }
573-
]
574-
end
575-
576-
IndexDefinition.new(table_name, index_name, unique, columns, [], orders, where, nil, using.to_sym, comment.presence)
577-
end.compact
578-
end
579-
580525
# @private
581526
def column_name_for_operation(operation, node)
582527
case operation

0 commit comments

Comments
 (0)