Commit 343591ed authored by Shinya Maeda's avatar Shinya Maeda

Add FK for deployments.environment_id to environments table

This commit adds the foreign key for the environment_id
column, which is long overdue.

Changelog: other
parent 53bc903b
# 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
...@@ -25507,6 +25507,9 @@ CREATE TRIGGER trigger_has_external_wiki_on_update AFTER UPDATE ON services FOR ...@@ -25507,6 +25507,9 @@ CREATE TRIGGER trigger_has_external_wiki_on_update AFTER UPDATE ON services FOR
ALTER TABLE ONLY chat_names ALTER TABLE ONLY chat_names
ADD CONSTRAINT fk_00797a2bf9 FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE CASCADE; 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 ALTER TABLE ONLY epics
ADD CONSTRAINT fk_013c9f36ca FOREIGN KEY (due_date_sourcing_epic_id) REFERENCES epics(id) ON DELETE SET NULL; 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 ...@@ -34,7 +34,7 @@ RSpec.describe 'Database schema' do
compliance_management_frameworks: %w[group_id], compliance_management_frameworks: %w[group_id],
commit_user_mentions: %w[commit_id], commit_user_mentions: %w[commit_id],
deploy_keys_projects: %w[deploy_key_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], draft_notes: %w[discussion_id commit_id],
epics: %w[updated_by_id last_edited_by_id state_id], epics: %w[updated_by_id last_edited_by_id state_id],
events: %w[target_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