Commit 4c56f7a1 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'yorick/auto-rollback-cross-database' into 'master'

Use loose foreign keys for Terraform state versions

See merge request gitlab-org/gitlab!74524
parents d96d980d 7fa3cb45
...@@ -59,7 +59,7 @@ module Ci ...@@ -59,7 +59,7 @@ module Ci
has_one :runner_session, class_name: 'Ci::BuildRunnerSession', validate: true, inverse_of: :build has_one :runner_session, class_name: 'Ci::BuildRunnerSession', validate: true, inverse_of: :build
has_one :trace_metadata, class_name: 'Ci::BuildTraceMetadata', inverse_of: :build has_one :trace_metadata, class_name: 'Ci::BuildTraceMetadata', inverse_of: :build
has_many :terraform_state_versions, class_name: 'Terraform::StateVersion', dependent: :nullify, inverse_of: :build, foreign_key: :ci_build_id # rubocop:disable Cop/ActiveRecordDependent has_many :terraform_state_versions, class_name: 'Terraform::StateVersion', inverse_of: :build, foreign_key: :ci_build_id
accepts_nested_attributes_for :runner_session, update_only: true accepts_nested_attributes_for :runner_session, update_only: true
accepts_nested_attributes_for :job_variables accepts_nested_attributes_for :job_variables
......
...@@ -41,3 +41,7 @@ pages_deployments: ...@@ -41,3 +41,7 @@ pages_deployments:
- table: ci_builds - table: ci_builds
column: ci_build_id column: ci_build_id
on_delete: async_nullify on_delete: async_nullify
terraform_state_versions:
- table: ci_builds
column: ci_build_id
on_delete: async_nullify
...@@ -81,7 +81,6 @@ RSpec.describe 'Database schema' do ...@@ -81,7 +81,6 @@ RSpec.describe 'Database schema' do
subscriptions: %w[user_id subscribable_id], subscriptions: %w[user_id subscribable_id],
suggestions: %w[commit_id], suggestions: %w[commit_id],
taggings: %w[tag_id taggable_id tagger_id], taggings: %w[tag_id taggable_id tagger_id],
terraform_state_versions: %w[ci_build_id],
timelogs: %w[user_id], timelogs: %w[user_id],
todos: %w[target_id commit_id], todos: %w[target_id commit_id],
uploads: %w[model_id], uploads: %w[model_id],
......
...@@ -29,7 +29,7 @@ RSpec.describe Ci::Build do ...@@ -29,7 +29,7 @@ RSpec.describe Ci::Build do
it { is_expected.to have_one(:deployment) } it { is_expected.to have_one(:deployment) }
it { is_expected.to have_one(:runner_session) } it { is_expected.to have_one(:runner_session) }
it { is_expected.to have_one(:trace_metadata) } it { is_expected.to have_one(:trace_metadata) }
it { is_expected.to have_many(:terraform_state_versions).dependent(:nullify).inverse_of(:build) } it { is_expected.to have_many(:terraform_state_versions).inverse_of(:build) }
it { is_expected.to validate_presence_of(:ref) } it { is_expected.to validate_presence_of(:ref) }
......
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