]> git.openstreetmap.org Git - rails.git/commitdiff
Add a remove_foreign_key method and make migration 34 reversible.
authorTom Hughes <tom@compton.nu>
Sun, 31 May 2009 13:53:16 +0000 (13:53 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 31 May 2009 13:53:16 +0000 (13:53 +0000)
db/migrate/034_create_languages.rb
lib/migrate.rb

index 4b45ce33fb206198e2b166045e0c3fc279fe15c6..17f5efe027e37d4b12bc44175ba8f73bed2561aa 100644 (file)
@@ -23,7 +23,10 @@ class CreateLanguages < ActiveRecord::Migration
   end
 
   def self.down
-    raise IrreversibleMigration.new
+    remove_foreign_key :diary_entries, [:language_code], :languages, [:code]
+    remove_foreign_key :users, [:locale], :languages, [:code]
+
+    drop_table :languages
   end
 end
 
index 05b3c90f24da86a9cf541ec9cf60c7e90c9c7520..50ba6321dc24ffea9e7388137433f1b370e51f4c 100644 (file)
@@ -21,6 +21,11 @@ module ActiveRecord
          "REFERENCES #{reftbl} (#{quote_column_names(refcol || column_name)})"
       end
 
+      def remove_foreign_key(table_name, column_name, reftbl, refcol = nil)
+        execute "ALTER TABLE #{table_name} DROP " +
+          "CONSTRAINT #{table_name}_#{column_name[0]}_fkey"
+      end
+
       alias_method :old_options_include_default?, :options_include_default?
 
       def options_include_default?(options)