class AddTypeToRelationships < ActiveRecord::Migration[5.2]
  def up
    add_column :relationships, :type, :string

    execute %(delete from relationships where source_id = target_id)

    execute %(update relationships set type = 'Relationships::Follow')

    change_column_null :relationships, :type, false
    add_index :relationships, :type
  end

  def down
    execute %(delete from relationships where type <> 'Relationships::Follow')

    remove_column :relationships, :type
  end
end

class AddTypeToRelationships < ActiveRecord::Migration[5.2]
  def up
    add_column :relationships, :type, :string

    execute %(update relationships set type = 'Relationships::Follow')

    change_column_null :relationships, :type, false
    add_index :relationships, :type
  end

  def down
    execute %(delete from relationships where type <> 'Relationships::Follow')

    remove_column :relationships, :type
  end
end

--- 
+++ 
@@ -1,6 +1,8 @@
 class AddTypeToRelationships < ActiveRecord::Migration[5.2]
   def up
     add_column :relationships, :type, :string
+
+    execute %(delete from relationships where source_id = target_id)
 
     execute %(update relationships set type = 'Relationships::Follow')
 
Remove relationships where source == target prior to adding relationship type
