debian-mirror-gitlab/db/migrate/20210430124630_add_devops_adoption_indexes.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
1.6 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
class AddDevopsAdoptionIndexes < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
SEGMENTS_INDEX_NAME = 'idx_devops_adoption_segments_namespaces_pair'
SNAPSHOT_END_TIME_INDEX_NAME = 'idx_devops_adoption_segments_namespace_end_time'
SNAPSHOT_RECORDED_AT_INDEX_NAME = 'idx_devops_adoption_segments_namespace_recorded_at'
def up
add_concurrent_index :analytics_devops_adoption_snapshots, [:namespace_id, :end_time],
name: SNAPSHOT_END_TIME_INDEX_NAME
add_concurrent_index :analytics_devops_adoption_snapshots, [:namespace_id, :recorded_at],
name: SNAPSHOT_RECORDED_AT_INDEX_NAME
add_concurrent_index :analytics_devops_adoption_segments, [:display_namespace_id, :namespace_id],
unique: true, name: SEGMENTS_INDEX_NAME
add_concurrent_foreign_key :analytics_devops_adoption_snapshots, :namespaces, column: :namespace_id
add_concurrent_foreign_key :analytics_devops_adoption_segments, :namespaces, column: :display_namespace_id
end
def down
remove_foreign_key :analytics_devops_adoption_segments, :namespaces, column: :display_namespace_id
remove_foreign_key :analytics_devops_adoption_snapshots, :namespaces, column: :namespace_id
remove_concurrent_index_by_name :analytics_devops_adoption_segments, SEGMENTS_INDEX_NAME
remove_concurrent_index_by_name :analytics_devops_adoption_snapshots, SNAPSHOT_RECORDED_AT_INDEX_NAME
remove_concurrent_index_by_name :analytics_devops_adoption_snapshots, SNAPSHOT_END_TIME_INDEX_NAME
end
end