diff options
author | Heinrich Lee Yu <heinrich@gitlab.com> | 2019-07-24 17:36:39 +0300 |
---|---|---|
committer | Heinrich Lee Yu <heinrich@gitlab.com> | 2019-08-05 12:49:24 +0300 |
commit | 3f9b1ecdb3bbaab6ec35d28d066759985ce25e0e (patch) | |
tree | 32edef8386900cba11fbe38e53638ccfeb8134d5 /db/migrate | |
parent | afbe0b616b1e17f88bacc283a7a8fbe0bece580a (diff) |
Use SQL to find the gap instead of iterating
Also removes unnecessary methods causing extra queries
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/20190802012622_reorder_issues_project_id_relative_position_index.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/db/migrate/20190802012622_reorder_issues_project_id_relative_position_index.rb b/db/migrate/20190802012622_reorder_issues_project_id_relative_position_index.rb new file mode 100644 index 00000000000..12088dd763f --- /dev/null +++ b/db/migrate/20190802012622_reorder_issues_project_id_relative_position_index.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class ReorderIssuesProjectIdRelativePositionIndex < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_issues_on_project_id_and_state_and_rel_position_and_id' + NEW_INDEX_NAME = 'index_issues_on_project_id_and_rel_position_and_state_and_id' + + def up + add_concurrent_index :issues, [:project_id, :relative_position, :state, :id], order: { id: :desc }, name: NEW_INDEX_NAME + + remove_concurrent_index_by_name :issues, OLD_INDEX_NAME + end + + def down + add_concurrent_index :issues, [:project_id, :state, :relative_position, :id], order: { id: :desc }, name: OLD_INDEX_NAME + + remove_concurrent_index_by_name :issues, NEW_INDEX_NAME + end +end |