debian-mirror-gitlab/db/migrate/20200123090839_remove_analytics_repository_table_fks_on_projects.rb

31 lines
1.1 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
class RemoveAnalyticsRepositoryTableFksOnProjects < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
2021-01-03 14:25:43 +05:30
disable_ddl_transaction!
2020-03-13 15:44:24 +05:30
def up
2021-01-03 14:25:43 +05:30
# Requires ExclusiveLock on all tables. analytics_* tables are empty
2020-03-13 15:44:24 +05:30
with_lock_retries do
2021-01-03 14:25:43 +05:30
remove_foreign_key_if_exists(:analytics_repository_files, :projects)
2020-03-13 15:44:24 +05:30
end
with_lock_retries do
2021-01-03 14:25:43 +05:30
remove_foreign_key_if_exists(:analytics_repository_file_edits, :projects) if table_exists?(:analytics_repository_file_edits) # this table might be already dropped on development environment
2020-03-13 15:44:24 +05:30
end
2021-01-03 14:25:43 +05:30
with_lock_retries do
remove_foreign_key_if_exists(:analytics_repository_file_commits, :projects)
end
end
def down
add_concurrent_foreign_key(:analytics_repository_files, :projects, column: :project_id, on_delete: :cascade)
add_concurrent_foreign_key(:analytics_repository_file_edits, :projects, column: :project_id, on_delete: :cascade)
add_concurrent_foreign_key(:analytics_repository_file_commits, :projects, column: :project_id, on_delete: :cascade)
2020-03-13 15:44:24 +05:30
end
end