Commit 363fad24 authored by Alper Akgun's avatar Alper Akgun

Merge branch 'add-fk-to-deployments-environment-id' into 'master'

Add FK for deployments.environment_id to environments table

See merge request gitlab-org/gitlab!64585
parents f1deba57 343591ed
# 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
e43889baa57ea2cd0b87ba98819408115955f6a6586b3275cf0a08bd79909c71
\ No newline at end of file
......@@ -25476,6 +25476,9 @@ CREATE TRIGGER trigger_has_external_wiki_on_update AFTER UPDATE ON services FOR
ALTER TABLE ONLY chat_names
ADD CONSTRAINT fk_00797a2bf9 FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE CASCADE;
ALTER TABLE ONLY deployments
ADD CONSTRAINT fk_009fd21147 FOREIGN KEY (environment_id) REFERENCES environments(id) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY epics
ADD CONSTRAINT fk_013c9f36ca FOREIGN KEY (due_date_sourcing_epic_id) REFERENCES epics(id) ON DELETE SET NULL;
......@@ -34,7 +34,7 @@ RSpec.describe 'Database schema' do
compliance_management_frameworks: %w[group_id],
commit_user_mentions: %w[commit_id],
deploy_keys_projects: %w[deploy_key_id],
deployments: %w[deployable_id environment_id user_id],
deployments: %w[deployable_id user_id],
draft_notes: %w[discussion_id commit_id],
epics: %w[updated_by_id last_edited_by_id state_id],
events: %w[target_id],
......
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