From: Tom Hughes Date: Sun, 31 May 2009 13:53:16 +0000 (+0000) Subject: Add a remove_foreign_key method and make migration 34 reversible. X-Git-Tag: live~7883^2~23 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/098e757cf28c2f931e7234b68197115f681a2ce5 Add a remove_foreign_key method and make migration 34 reversible. --- diff --git a/db/migrate/034_create_languages.rb b/db/migrate/034_create_languages.rb index 4b45ce33f..17f5efe02 100644 --- a/db/migrate/034_create_languages.rb +++ b/db/migrate/034_create_languages.rb @@ -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 diff --git a/lib/migrate.rb b/lib/migrate.rb index 05b3c90f2..50ba6321d 100644 --- a/lib/migrate.rb +++ b/lib/migrate.rb @@ -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)