class TidyUpBecauseOfBadException < ActiveRecord::Migration[4.2]
  def change
    if Hyrax::PermissionTemplate.column_names.include?('workflow_id')
      Hyrax::PermissionTemplate.all.each do |permission_template|
        workflow_id = permission_template.workflow_id
        next unless workflow_id
        Sipity::Workflow.find(workflow_id).update(active: true)
      end

      remove_column Hyrax::PermissionTemplate.table_name, :workflow_id
    end
  end
end

class TidyUpBecauseOfBadException < ActiveRecord::Migration[4.2]
  def change
    if column_exists?(Hyrax::PermissionTemplate.table_name, :workflow_id)
      Hyrax::PermissionTemplate.all.each do |permission_template|
        workflow_id = permission_template.workflow_id
        next unless workflow_id
        Sipity::Workflow.find(workflow_id).update(active: true)
      end

      remove_column Hyrax::PermissionTemplate.table_name, :workflow_id
    end
  end
end

Use `column_exists?` to see if `:workflow_id` is present
Use `column_exists?` to see if `:workflow_id` is present

Using the `column_names` method on the `Hyrax::PermissionTemplate` class leads to false positives, which lead to exceptions. Now it is possible for Hyrax-based apps to run `rails db:drop db:create db:migrate` without errors.

Tested in, and ported from, Hyku: https://github.com/projecthydra-labs/hyku/pull/1010
