Commit 2a087ad3 authored by Lee Tickett's avatar Lee Tickett Committed by Andreas Brandl

Drop forked_project_links table

parent 3765eb1d
---
title: Drop forked_project_links table
merge_request: 20771
author: Lee Tickett
type: other
# frozen_string_literal: true
class DropForkedProjectLinksFk < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
with_lock_retries do
remove_foreign_key_if_exists :forked_project_links, column: :forked_to_project_id
end
end
def down
unless foreign_key_exists?(:forked_project_links, :projects, column: :forked_to_project_id)
with_lock_retries do
# rubocop: disable Migration/AddConcurrentForeignKey
add_foreign_key :forked_project_links, :projects, column: :forked_to_project_id, on_delete: :cascade, validate: false
end
end
fk_name = concurrent_foreign_key_name(:forked_project_links, :forked_to_project_id, prefix: 'fk_rails_')
validate_foreign_key(:forked_project_links, :forked_to_project_id, name: fk_name)
end
end
# frozen_string_literal: true
class DropForkedProjectLinksTable < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
drop_table "forked_project_links", id: :serial do |t|
t.integer "forked_to_project_id", null: false
t.integer "forked_from_project_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.index ["forked_to_project_id"], name: "index_forked_project_links_on_forked_to_project_id", unique: true
end
end
end
...@@ -1654,14 +1654,6 @@ ActiveRecord::Schema.define(version: 2020_02_20_180944) do ...@@ -1654,14 +1654,6 @@ ActiveRecord::Schema.define(version: 2020_02_20_180944) do
t.index ["root_project_id"], name: "index_fork_networks_on_root_project_id", unique: true t.index ["root_project_id"], name: "index_fork_networks_on_root_project_id", unique: true
end end
create_table "forked_project_links", id: :serial, force: :cascade do |t|
t.integer "forked_to_project_id", null: false
t.integer "forked_from_project_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.index ["forked_to_project_id"], name: "index_forked_project_links_on_forked_to_project_id", unique: true
end
create_table "geo_cache_invalidation_events", force: :cascade do |t| create_table "geo_cache_invalidation_events", force: :cascade do |t|
t.string "key", null: false t.string "key", null: false
end end
...@@ -4747,7 +4739,6 @@ ActiveRecord::Schema.define(version: 2020_02_20_180944) do ...@@ -4747,7 +4739,6 @@ ActiveRecord::Schema.define(version: 2020_02_20_180944) do
add_foreign_key "fork_network_members", "projects", column: "forked_from_project_id", name: "fk_b01280dae4", on_delete: :nullify add_foreign_key "fork_network_members", "projects", column: "forked_from_project_id", name: "fk_b01280dae4", on_delete: :nullify
add_foreign_key "fork_network_members", "projects", on_delete: :cascade add_foreign_key "fork_network_members", "projects", on_delete: :cascade
add_foreign_key "fork_networks", "projects", column: "root_project_id", name: "fk_e7b436b2b5", on_delete: :nullify add_foreign_key "fork_networks", "projects", column: "root_project_id", name: "fk_e7b436b2b5", on_delete: :nullify
add_foreign_key "forked_project_links", "projects", column: "forked_to_project_id", name: "fk_434510edb0", on_delete: :cascade
add_foreign_key "geo_container_repository_updated_events", "container_repositories", name: "fk_212c89c706", on_delete: :cascade add_foreign_key "geo_container_repository_updated_events", "container_repositories", name: "fk_212c89c706", on_delete: :cascade
add_foreign_key "geo_event_log", "geo_cache_invalidation_events", column: "cache_invalidation_event_id", name: "fk_42c3b54bed", on_delete: :cascade add_foreign_key "geo_event_log", "geo_cache_invalidation_events", column: "cache_invalidation_event_id", name: "fk_42c3b54bed", on_delete: :cascade
add_foreign_key "geo_event_log", "geo_container_repository_updated_events", column: "container_repository_updated_event_id", name: "fk_6ada82d42a", on_delete: :cascade add_foreign_key "geo_event_log", "geo_container_repository_updated_events", column: "container_repository_updated_event_id", name: "fk_6ada82d42a", on_delete: :cascade
......
...@@ -235,11 +235,17 @@ module Gitlab ...@@ -235,11 +235,17 @@ module Gitlab
# PostgreSQL constraint names have a limit of 63 bytes. The logic used # PostgreSQL constraint names have a limit of 63 bytes. The logic used
# here is based on Rails' foreign_key_name() method, which unfortunately # here is based on Rails' foreign_key_name() method, which unfortunately
# is private so we can't rely on it directly. # is private so we can't rely on it directly.
def concurrent_foreign_key_name(table, column) #
# prefix:
# - The default prefix is `fk_` for backward compatibility with the existing
# concurrent foreign key helpers.
# - For standard rails foreign keys the prefix is `fk_rails_`
#
def concurrent_foreign_key_name(table, column, prefix: 'fk_')
identifier = "#{table}_#{column}_fk" identifier = "#{table}_#{column}_fk"
hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10) hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10)
"fk_#{hashed_identifier}" "#{prefix}#{hashed_identifier}"
end end
# Long-running migrations may take more than the timeout allowed by # Long-running migrations may take more than the timeout allowed by
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment