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-07-13 12:10:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-13 12:10:21 +0300
commita4772171f93e06dcc4bbc78a3577b1faa7dd1f50 (patch)
tree33c6a1d0278581ff3140730b46f57df15b85cc85 /db
parenta48b98b75db31df0c4feea4b4bb3e3afd7ce73cf (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20230712064637_replace_old_fk_p_ci_builds_metadata_to_builds_v2.rb54
-rw-r--r--db/post_migrate/20230712064655_replace_old_fk_p_ci_runner_machine_builds_to_builds_v2.rb54
-rw-r--r--db/schema_migrations/202307120646371
-rw-r--r--db/schema_migrations/202307120646551
4 files changed, 110 insertions, 0 deletions
diff --git a/db/post_migrate/20230712064637_replace_old_fk_p_ci_builds_metadata_to_builds_v2.rb b/db/post_migrate/20230712064637_replace_old_fk_p_ci_builds_metadata_to_builds_v2.rb
new file mode 100644
index 00000000000..6165029d855
--- /dev/null
+++ b/db/post_migrate/20230712064637_replace_old_fk_p_ci_builds_metadata_to_builds_v2.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkPCiBuildsMetadataToBuildsV2 < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :p_ci_builds_metadata, :ci_builds,
+ name: :fk_e20479742e_p, reverse_lock_order: true
+
+ rename_constraint :p_ci_builds_metadata, :temp_fk_e20479742e_p, :fk_e20479742e_p
+
+ Gitlab::Database::PostgresPartitionedTable.each_partition(:p_ci_builds_metadata) do |partition|
+ rename_constraint partition.identifier, :temp_fk_e20479742e_p, :fk_e20479742e_p
+ end
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_partitioned_foreign_key :p_ci_builds_metadata, :ci_builds,
+ name: :temp_fk_e20479742e_p,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :p_ci_builds_metadata, :fk_e20479742e_p, :temp_fk_e20479742e_p
+
+ Gitlab::Database::PostgresPartitionedTable.each_partition(:p_ci_builds_metadata) do |partition|
+ switch_constraint_names partition.identifier, :fk_e20479742e_p, :temp_fk_e20479742e_p
+ end
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_builds_metadata, :ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:p_ci_builds_metadata, :p_ci_builds, name: :fk_e20479742e_p)
+ end
+end
diff --git a/db/post_migrate/20230712064655_replace_old_fk_p_ci_runner_machine_builds_to_builds_v2.rb b/db/post_migrate/20230712064655_replace_old_fk_p_ci_runner_machine_builds_to_builds_v2.rb
new file mode 100644
index 00000000000..8f1c1872e04
--- /dev/null
+++ b/db/post_migrate/20230712064655_replace_old_fk_p_ci_runner_machine_builds_to_builds_v2.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkPCiRunnerMachineBuildsToBuildsV2 < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :p_ci_runner_machine_builds, :ci_builds,
+ name: :fk_bb490f12fe_p, reverse_lock_order: true
+
+ rename_constraint :p_ci_runner_machine_builds, :temp_fk_bb490f12fe_p, :fk_bb490f12fe_p
+
+ Gitlab::Database::PostgresPartitionedTable.each_partition(:p_ci_runner_machine_builds) do |partition|
+ rename_constraint partition.identifier, :temp_fk_bb490f12fe_p, :fk_bb490f12fe_p
+ end
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_partitioned_foreign_key :p_ci_runner_machine_builds, :ci_builds,
+ name: :temp_fk_bb490f12fe_p,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :p_ci_runner_machine_builds, :fk_bb490f12fe_p, :temp_fk_bb490f12fe_p
+
+ Gitlab::Database::PostgresPartitionedTable.each_partition(:p_ci_runner_machine_builds) do |partition|
+ switch_constraint_names partition.identifier, :fk_bb490f12fe_p, :temp_fk_bb490f12fe_p
+ end
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:p_ci_runner_machine_builds, :p_ci_builds, name: :fk_bb490f12fe_p)
+ end
+end
diff --git a/db/schema_migrations/20230712064637 b/db/schema_migrations/20230712064637
new file mode 100644
index 00000000000..7b541ed714d
--- /dev/null
+++ b/db/schema_migrations/20230712064637
@@ -0,0 +1 @@
+b39d83cc2257d75ece3dfa1c5f6faa1ef6eb1c40d3de0a1899a2860d5a1c7ed1 \ No newline at end of file
diff --git a/db/schema_migrations/20230712064655 b/db/schema_migrations/20230712064655
new file mode 100644
index 00000000000..860b5183a04
--- /dev/null
+++ b/db/schema_migrations/20230712064655
@@ -0,0 +1 @@
+25d0b4c560dcec564a268d96e969b07fbfe18f1d902fdafe415cf747bdb1302c \ No newline at end of file