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
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20210622135221_add_foreign_key_for_environment_id_to_environments.rb')
-rw-r--r--db/migrate/20210622135221_add_foreign_key_for_environment_id_to_environments.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/db/migrate/20210622135221_add_foreign_key_for_environment_id_to_environments.rb b/db/migrate/20210622135221_add_foreign_key_for_environment_id_to_environments.rb
new file mode 100644
index 00000000000..03991cea41c
--- /dev/null
+++ b/db/migrate/20210622135221_add_foreign_key_for_environment_id_to_environments.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddForeignKeyForEnvironmentIdToEnvironments < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ # `validate: false` option is passed here, because validating the existing rows fails by the orphaned deployments,
+ # which will be cleaned up in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/64588.
+ # The validation runs for only new records or updates, so that we can at least
+ # stop creating orphaned rows.
+ add_concurrent_foreign_key :deployments, :environments, column: :environment_id, on_delete: :cascade, validate: false
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :deployments, :environments
+ end
+ end
+end