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
path: root/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-10-11 05:58:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-10-11 05:58:47 +0300
commit61b630468c6ad6c9bf06be8e9b02785c995f7a5a (patch)
tree0b770ff9ffa17fd5cf554695eb1381ce9187db4d /db
parent8b7cfdd3397edb18f0e0d4f1c71d6b9282f68aef (diff)
Add latest changes from gitlab-org/gitlab@16-4-stable-ee
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20230823145126_swap_notes_id_to_bigint_for_self_managed.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/db/post_migrate/20230823145126_swap_notes_id_to_bigint_for_self_managed.rb b/db/post_migrate/20230823145126_swap_notes_id_to_bigint_for_self_managed.rb
index ddfaefc452b..988adff7d79 100644
--- a/db/post_migrate/20230823145126_swap_notes_id_to_bigint_for_self_managed.rb
+++ b/db/post_migrate/20230823145126_swap_notes_id_to_bigint_for_self_managed.rb
@@ -60,6 +60,10 @@ class SwapNotesIdToBigintForSelfManaged < Gitlab::Database::Migration[2.1]
[:timelogs, :fk_timelogs_note_id, :note_id, :nullify]
]
+ class PgForeignKeys < MigrationRecord
+ self.table_name = :postgres_foreign_keys
+ end
+
def up
return if com_or_dev_or_test_but_not_jh?
@@ -89,6 +93,8 @@ class SwapNotesIdToBigintForSelfManaged < Gitlab::Database::Migration[2.1]
replace_referencing_foreign_keys
+ find_and_drop_faulting_foreign_keys(:system_note_metadata, :fk_d83a918cb1)
+
with_lock_retries(raise_on_exhaustion: true) do
# Swap the original and new column names
execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN id TO id_tmp"
@@ -180,4 +186,24 @@ class SwapNotesIdToBigintForSelfManaged < Gitlab::Database::Migration[2.1]
end
end
end
+
+ # Customers reported that some FKs are blocking the +notes_pkey+ to be dropped. This is happening, because some
+ # foreign keys listed in +REFERENCING_FOREIGN_KEYS+ have different names in customers instances.
+ # We need to find and remove this FKs to finish the swapping process.
+ #
+ # @info https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/8227
+ def find_and_drop_faulting_foreign_keys(constrained_table, referenced_fk_name)
+ foreign_keys = PgForeignKeys.select(:name)
+ .where(constrained_table_name: constrained_table)
+ .where(referenced_table_name: TABLE_NAME)
+ .where.not(name: referenced_fk_name)
+
+ with_lock_retries(raise_on_exhaustion: true) do
+ execute "LOCK TABLE #{TABLE_NAME}, #{constrained_table} IN ACCESS EXCLUSIVE MODE"
+
+ foreign_keys.each do |foreign_key|
+ remove_foreign_key_if_exists(constrained_table, name: foreign_key.name)
+ end
+ end
+ end
end