]> git.openstreetmap.org Git - rails.git/blobdiff - lib/migrate.rb
Cope with sessions which don't exist.
[rails.git] / lib / migrate.rb
index 392060b6015a8cdb34d5fcfa6172e8a215b05eb4..05b3c90f24da86a9cf541ec9cf60c7e90c9c7520 100644 (file)
@@ -158,6 +158,21 @@ module ActiveRecord
       def interval_constant(interval)
         "'#{interval}'::interval"
       end
       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
     end
   end
 end