gitlab-org--gitlab-foss/db/migrate/20190826100605_add_group_column_to_events.rb
Jan Provaznik b9657ed1e0 Add index on group_id column concurrently
This fixes previously added migration which caused timeouts on
big events table.
2019-09-10 11:52:48 +00:00

19 lines
522 B
Ruby

# frozen_string_literal: true
class AddGroupColumnToEvents < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
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