aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
diff options
context:
space:
mode:
authordoabit <doinsist@gmail.com>2013-03-24 05:09:54 +0800
committerdoabit <doinsist@gmail.com>2013-03-24 05:09:54 +0800
commit8094156728f72d493916e3d3a8c8d90c5f2d79c0 (patch)
tree4772eec9db0ed9316941aee23fa5dd038587b3f9 /activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
parent9e8b7d9d5bb3537f113fbda2a1720c5f412fbe62 (diff)
downloadrails-8094156728f72d493916e3d3a8c8d90c5f2d79c0.tar.gz
rails-8094156728f72d493916e3d3a8c8d90c5f2d79c0.tar.bz2
rails-8094156728f72d493916e3d3a8c8d90c5f2d79c0.zip
Custom index type support with :using.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb12
1 files changed, 11 insertions, 1 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 0622d0a909..688bf1774b 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -160,8 +160,9 @@ module ActiveRecord
desc_order_columns = inddef.scan(/(\w+) DESC/).flatten
orders = desc_order_columns.any? ? Hash[desc_order_columns.map {|order_column| [order_column, :desc]}] : {}
where = inddef.scan(/WHERE (.+)$/).flatten[0]
+ type = inddef.scan(/USING (.+?) /).flatten[0].to_sym
- column_names.empty? ? nil : IndexDefinition.new(table_name, index_name, unique, column_names, [], orders, where)
+ column_names.empty? ? nil : IndexDefinition.new(table_name, index_name, unique, column_names, [], orders, where, type)
end.compact
end
@@ -408,6 +409,15 @@ module ActiveRecord
rename_column_indexes(table_name, column_name, new_column_name)
end
+ def add_index(table_name, column_name, options = {}) #:nodoc:
+ if options.is_a?(Hash) && options[:using]
+ index_name, index_type, index_columns, index_options = add_index_options(table_name, column_name, options)
+ execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} USING #{options[:using]} (#{index_columns})#{index_options}"
+ else
+ super
+ end
+ end
+
def remove_index!(table_name, index_name) #:nodoc:
execute "DROP INDEX #{quote_table_name(index_name)}"
end