class RemoveOldTagsForeignKey < ActiveRecord::Migration
    def self.up
        if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
            execute "ALTER TABLE has_tag_string_tags DROP CONSTRAINT fk_public_body_tags_public_body"
        end

        # This table was already removed in the previous migration
        # remove_index :public_body_tags, [:public_body_id, :name, :value]
        # remove_index :public_body_tags, :name

        add_index :has_tag_string_tags, [:model, :model_id, :name, :value], :name => 'by_model_and_model_id_and_name_and_value'
        add_index :has_tag_string_tags, :name
    end

    def self.down
        raise "no reverse migration"
    end
end

class RemoveOldTagsForeignKey < ActiveRecord::Migration
    def self.up
        if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
            execute "ALTER TABLE has_tag_string_tags DROP CONSTRAINT fk_public_body_tags_public_body"
        end

        remove_index :public_body_tags, [:public_body_id, :name, :value]
        remove_index :public_body_tags, :name

        add_index :has_tag_string_tags, [:model, :model_id, :name, :value]
        add_index :has_tag_string_tags, :name
    end

    def self.down
        raise "no reverse migration"
    end
end

--- 
+++ 
@@ -4,10 +4,11 @@
             execute "ALTER TABLE has_tag_string_tags DROP CONSTRAINT fk_public_body_tags_public_body"
         end
 
-        remove_index :public_body_tags, [:public_body_id, :name, :value]
-        remove_index :public_body_tags, :name
+        # This table was already removed in the previous migration
+        # remove_index :public_body_tags, [:public_body_id, :name, :value]
+        # remove_index :public_body_tags, :name
 
-        add_index :has_tag_string_tags, [:model, :model_id, :name, :value]
+        add_index :has_tag_string_tags, [:model, :model_id, :name, :value], :name => 'by_model_and_model_id_and_name_and_value'
         add_index :has_tag_string_tags, :name
     end
 
Fix up some DB migration issues with Rails 3

* The public_body_tags table had already been removed
* The index has_tag_string_tags generated a name longer than the Postgres maximum of 63 characters. It was ignored in earlier Rails versions, see: https://rails.lighthouseapp.com/projects/8994/tickets/6187-postgresql-and-rails-303-migrations-fail-with-index-name-length-64-chars
