Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2019-09-10 14:52:48 +0300
committerAndreas Brandl <abrandl@gitlab.com>2019-09-10 14:52:48 +0300
commitb9657ed1e0c65ce132bf35162fd81fb65ccbff88 (patch)
tree34e31751ac481d63b7e0dba27d63f3e557677c86 /db/migrate/20190826100605_add_group_column_to_events.rb
parenteb2afea2abaa61978fae312a5a9b71293ab0e84a (diff)
Add index on group_id column concurrently
This fixes previously added migration which caused timeouts on big events table.
Diffstat (limited to 'db/migrate/20190826100605_add_group_column_to_events.rb')
-rw-r--r--db/migrate/20190826100605_add_group_column_to_events.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/db/migrate/20190826100605_add_group_column_to_events.rb b/db/migrate/20190826100605_add_group_column_to_events.rb
index cd7b2b1d96a..dfc9d8cbdf1 100644
--- a/db/migrate/20190826100605_add_group_column_to_events.rb
+++ b/db/migrate/20190826100605_add_group_column_to_events.rb
@@ -1,9 +1,19 @@
# frozen_string_literal: true
class AddGroupColumnToEvents < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
DOWNTIME = false
- def change
- add_reference :events, :group, index: true, foreign_key: { to_table: :namespaces, on_delete: :cascade }
+ disable_ddl_transaction!
+
+ def up
+ add_column(:events, :group_id, :bigint) unless column_exists?(:events, :group_id)
+ add_concurrent_index(:events, :group_id)
+ add_concurrent_foreign_key(:events, :namespaces, column: :group_id, on_delete: :cascade)
+ end
+
+ def down
+ remove_column(:events, :group_id) if column_exists?(:events, :group_id)
end
end