Sha256: 81883ef94611bc91c136f840cf10f59f3dbcf3ae392b7dc3466be40786e9ee20

Contents?: true

Size: 1.47 KB

Versions: 20

Compression:

Stored size: 1.47 KB

Contents

class AddMissingIndexes < ActiveRecord::Migration
  # 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

20 entries across 20 versions & 1 rubygems

Version Path
foreman-tasks-0.10.9 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.10.8 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.10.7 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.10.6 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.10.4 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.9.6 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.10.3 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.10.2 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.10.1 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.9.5 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.10.0 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.9.4 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.9.3 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.9.2 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.9.1 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.9.0 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.8.6 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.8.5 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.8.4 db/migrate/20161003091412_add_missing_indexes.rb
foreman-tasks-0.8.3 db/migrate/20161003091412_add_missing_indexes.rb