-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data migration to nullify target fields on bs_request_actions
Nullify `target_project_id` and `target_package_id` in `bs_request_actions` if the project or/and package no longer exist.
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/api/db/data/20250131094818_nullify_targets_on_bs_request_actions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
class NullifyTargetsOnBsRequestActions < ActiveRecord::Migration[7.0] | ||
# rubocop:disable Rails/SkipsModelValidations | ||
def up | ||
bs_request_actions = BsRequestAction.where('target_project_id IS NOT NULL AND target_package_id IS NULL') | ||
bs_request_actions.in_batches do |batch| | ||
batch.find_each do |action| | ||
target_project = Project.find_by_name(action.target_project) | ||
if target_project.nil? | ||
action.update_attribute(:target_project_id, nil) | ||
end | ||
end | ||
end | ||
|
||
bs_request_actions = BsRequestAction.where('target_project_id IS NOT NULL AND target_package_id IS NOT NULL') | ||
bs_request_actions.in_batches do |batch| | ||
batch.find_each do |action| | ||
target_project = Project.find_by_name(action.target_project) | ||
if target_project.nil? | ||
action.update_attribute(:target_project_id, nil) | ||
action.update_attribute(:target_package_id, nil) | ||
next | ||
end | ||
|
||
target_package = Package.find_by_project_and_name(action.target_project, action.target_package) | ||
if target_package.nil? | ||
action.update_attribute(:target_package_id, nil) | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable Rails/SkipsModelValidations | ||
|
||
def down | ||
raise ActiveRecord::IrreversibleMigration | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
DataMigrate::Data.define(version: 20241017123303) | ||
DataMigrate::Data.define(version: 20250131094818) |