debian-mirror-gitlab/db/migrate/20180309160427_add_partial_indexes_on_todos.rb

30 lines
1.1 KiB
Ruby
Raw Normal View History

2018-03-27 19:54:05 +05:30
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
2019-02-15 15:39:39 +05:30
class AddPartialIndexesOnTodos < ActiveRecord::Migration[4.2]
2018-03-27 19:54:05 +05:30
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
2018-11-18 11:00:15 +05:30
disable_ddl_transaction!
INDEX_NAME_PENDING = "index_todos_on_user_id_and_id_pending"
INDEX_NAME_DONE = "index_todos_on_user_id_and_id_done"
2018-03-27 19:54:05 +05:30
def up
unless index_exists?(:todos, [:user_id, :id], name: INDEX_NAME_PENDING)
add_concurrent_index(:todos, [:user_id, :id], where: "state='pending'", name: INDEX_NAME_PENDING)
end
2018-11-18 11:00:15 +05:30
2018-03-27 19:54:05 +05:30
unless index_exists?(:todos, [:user_id, :id], name: INDEX_NAME_DONE)
add_concurrent_index(:todos, [:user_id, :id], where: "state='done'", name: INDEX_NAME_DONE)
end
end
def down
remove_concurrent_index(:todos, [:user_id, :id], where: "state='pending'", name: INDEX_NAME_PENDING)
remove_concurrent_index(:todos, [:user_id, :id], where: "state='done'", name: INDEX_NAME_DONE)
2018-11-18 11:00:15 +05:30
end
2018-03-27 19:54:05 +05:30
end