X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/a4de927a2800e0fc739460cee5a71e58d09d25f9..1b1b1b2f5729eb6e4ec990cae2d3ea834ea641d9:/lib/migrate.rb diff --git a/lib/migrate.rb b/lib/migrate.rb index 392060b60..05b3c90f2 100644 --- a/lib/migrate.rb +++ b/lib/migrate.rb @@ -158,6 +158,21 @@ module ActiveRecord def interval_constant(interval) "'#{interval}'::interval" end + + def add_index(table_name, column_name, options = {}) + column_names = Array(column_name) + index_name = index_name(table_name, :column => column_names) + + if Hash === options # legacy support, since this param was a string + index_type = options[:unique] ? "UNIQUE" : "" + index_name = options[:name] || index_name + index_method = options[:method] || "BTREE" + else + index_type = options + end + quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ") + execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} USING #{index_method} (#{quoted_column_names})" + end end end end