blob: 4baf8146b64e53287049fcb515c1a9b51cd57fbd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
class AddIndexesForUserActivityQueries < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :events, [:project_id, :author_id]
add_concurrent_index :user_interacted_projects, :user_id
end
def down
remove_concurrent_index :events, [:project_id, :author_id]
patch_foreign_keys do
remove_concurrent_index :user_interacted_projects, :user_id
end
end
private
def patch_foreign_keys
# MySQL doesn't like to remove the index with a foreign key using it.
remove_foreign_key :user_interacted_projects, :users unless Gitlab::Database.postgresql?
yield
# Let's re-add the foreign key using the existing index on (user_id, project_id)
add_concurrent_foreign_key :user_interacted_projects, :users, column: :user_id unless Gitlab::Database.postgresql?
end
end
|