diff options
author | Marcelo Silveira <marcelo@mhfs.com.br> | 2012-02-09 03:28:11 -0200 |
---|---|---|
committer | Marcelo Silveira <marcelo@mhfs.com.br> | 2012-02-09 03:28:11 -0200 |
commit | 7ef22fce7cdb955aba3b2f45629a711592336b1f (patch) | |
tree | 86362e8c3ec89afd925a593fb96a2dd8f8e6e3dc /activerecord/lib/active_record | |
parent | d70e0236df61d69c9299fe63df94da35c87ee2d8 (diff) | |
download | rails-7ef22fce7cdb955aba3b2f45629a711592336b1f.tar.gz rails-7ef22fce7cdb955aba3b2f45629a711592336b1f.tar.bz2 rails-7ef22fce7cdb955aba3b2f45629a711592336b1f.zip |
Made schema dumper recognize partial indices' where statements
Diffstat (limited to 'activerecord/lib/active_record')
3 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 132ca10f79..ad2e8634eb 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -6,7 +6,7 @@ require 'bigdecimal/util' module ActiveRecord module ConnectionAdapters #:nodoc: - class IndexDefinition < Struct.new(:table, :name, :unique, :columns, :lengths, :orders) #:nodoc: + class IndexDefinition < Struct.new(:table, :name, :unique, :columns, :lengths, :orders, :where) #:nodoc: end # Abstract representation of a column definition. Instances of this type diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index da5d6fcf3c..f1940ea15f 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -889,8 +889,9 @@ module ActiveRecord # add info on sort order for columns (only desc order is explicitly specified, asc is the default) 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] - column_names.empty? ? nil : IndexDefinition.new(table_name, index_name, unique, column_names, [], orders) + column_names.empty? ? nil : IndexDefinition.new(table_name, index_name, unique, column_names, [], orders, where) end.compact end diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index 2a565b51c6..dcbd165e58 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -197,6 +197,8 @@ HEADER index_orders = (index.orders || {}) statement_parts << (':order => ' + index.orders.inspect) unless index_orders.empty? + statement_parts << (':where => ' + index.where.inspect) if index.where + ' ' + statement_parts.join(', ') end |