Sha256: 8424dac4a1c2f30814f670fd6302efa1232daf62925e4b66814cc36cd953a1f2

Contents?: true

Size: 1.47 KB

Versions: 113

Compression:

Stored size: 1.47 KB

Contents

class AddMissingIndexes < ActiveRecord::Migration[4.2]
  # since this is just making sure the indexes we defined before are
  # really added we don't define the down direction here.
  # The support for defining index at column definition was added in Rails here
  # https://github.com/rails/rails/commit/9a0d35e820464f872b0340366dded639f00e19b9
  # We need to fix migrations that happened before Rails 4.2
  def up
    add_index_unless_exists(:foreman_tasks_task_groups, :type)
    add_index_unless_exists(:foreman_tasks_tasks, :id)
    add_index_unless_exists(:foreman_tasks_tasks, :type)
    add_index_unless_exists(:foreman_tasks_tasks, :label)
    add_index_unless_exists(:foreman_tasks_tasks, :started_at)
    add_index_unless_exists(:foreman_tasks_tasks, :start_at)
    add_index_unless_exists(:foreman_tasks_tasks, :start_before)
    add_index_unless_exists(:foreman_tasks_tasks, :ended_at)
    add_index_unless_exists(:foreman_tasks_tasks, :state)
    add_index_unless_exists(:foreman_tasks_tasks, :result)
    add_index_unless_exists(:foreman_tasks_tasks, :external_id)
    add_index_unless_exists(:foreman_tasks_tasks, :parent_task_id)
    add_index_unless_exists(:foreman_tasks_locks, :task_id)
    add_index_unless_exists(:foreman_tasks_locks, :name)
    add_index_unless_exists(:foreman_tasks_locks, :exclusive)
  end

  def add_index_unless_exists(table, attribute)
    unless indexes(table).any? { |index| index.columns == [attribute.to_s] }
      add_index(table, attribute)
    end
  end
end

Version data entries

113 entries across 113 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-10.0.1 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-10.0.0 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-9.2.3 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-9.2.2 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-9.2.1 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-9.2.0 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-9.1.1 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-9.0.4 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-9.1.0 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-9.0.2 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-9.0.1 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-8.3.3 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-9.0.0 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-8.2.1 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-8.1.4 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-8.3.2 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-8.3.1 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-8.1.3 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-8.3.0 db/migrate/20161003091412_add_missing_indexes.rb