-
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
36 additions
and
1 deletion.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
class NullifyTargetsOnBsRequestActions < ActiveRecord::Migration[7.0] | ||
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(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(target_package_id: nil, target_project_id: nil) | ||
next | ||
end | ||
|
||
target_package = Package.find_by_project_and_name(action.target_project, action.target_package) | ||
if target_package.nil? | ||
action.update(target_package_id: nil) | ||
end | ||
end | ||
end | ||
end | ||
|
||
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) |