generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For activities that will be continuing under DSIT: - change their transparency identifier to replace the string "GB-GOV-13" with "GB-GOV-26"; e.g. `GB-GOV-13-ISPF-UKSA-AH2TS7K-SPB9U87` becomes `GB-GOV-26-ISPF-UKSA-AH2TS7K-SPB9U87` - change the `providing_organisation_reference` for all their actuals, from "GB-GOV-13" to "GB-GOV-26" - change the `providing_organisation_reference` for all their forecasts, from "GB-GOV-13" to "GB-GOV-26" This type of data change would be better suited for a data migration or a rake task, but both of those would require access to the application console in the production environment.
- Loading branch information
1 parent
8ba7b20
commit 0004bbb
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
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
70 changes: 70 additions & 0 deletions
70
db/migrate/20240115183402_change_transparency_identifier.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,70 @@ | ||
class ChangeTransparencyIdentifier < ActiveRecord::Migration[6.1] | ||
def up | ||
continuing_activities = Export::ContinuingActivities.new.activities | ||
|
||
continuing_activities.each do |activity| | ||
original_previous_identifier = activity.previous_identifier.to_s | ||
original_transparency_identifier = activity.transparency_identifier.to_s | ||
updated_previous_identifier = original_transparency_identifier | ||
updated_transparency_identifier = original_transparency_identifier.sub(/\AGB-GOV-13/, "GB-GOV-26") | ||
|
||
if original_transparency_identifier == updated_transparency_identifier | ||
Rails.logger.info("Activity #{activity.roda_identifier} NO CHANGE: transparency_identifier=#{original_transparency_identifier}") | ||
elsif activity.update( | ||
previous_identifier: updated_previous_identifier, | ||
transparency_identifier: updated_transparency_identifier | ||
) | ||
message = "Activity #{activity.roda_identifier} UPDATED: previous_identifier=#{updated_previous_identifier} transparency_identifier=#{updated_transparency_identifier}" | ||
if original_previous_identifier | ||
message += " original previous_identifier=#{original_previous_identifier}" | ||
end | ||
Rails.logger.info(message) | ||
else | ||
Rails.logger.error("Activity #{activity.roda_identifier} UPDATE FAILED") | ||
end | ||
|
||
activity_actuals = activity.actuals.where(providing_organisation_reference: "GB-GOV-13") | ||
if activity_actuals.any? | ||
Rails.logger.info("Activity #{activity.roda_identifier}: Updating #{activity_actuals.count} actuals") | ||
|
||
activity_actuals.each do |actual| | ||
unless actual.update(providing_organisation_reference: "GB-GOV-26") | ||
Rails.logger.error("Activity #{activity.roda_identifier}: FAILED to update an actual: #{actual.id}") | ||
end | ||
end | ||
end | ||
|
||
activity_forecasts = Forecast.unscoped.where(parent_activity_id: activity.id, providing_organisation_reference: "GB-GOV-13") | ||
if activity_forecasts.any? | ||
Rails.logger.info("Activity #{activity.roda_identifier}: Updating #{activity_forecasts.count} forecasts") | ||
|
||
activity_forecasts.each do |forecast| | ||
unless forecast.update(providing_organisation_reference: "GB-GOV-26") | ||
Rails.logger.error("Activity #{activity.roda_identifier}: FAILED to update a forecast: #{forecast.id}") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
def down | ||
activities_to_restore = Export::ContinuingActivities.new.activities | ||
|
||
activities_to_restore.each do |activity| | ||
if activity.transparency_identifier | ||
activity.update( | ||
previous_identifier: nil, | ||
transparency_identifier: activity.transparency_identifier.sub(/\AGB-GOV-26/, "GB-GOV-13") | ||
) | ||
end | ||
|
||
activity.actuals.where(providing_organisation_reference: "GB-GOV-26").each do |actual| | ||
actual.update(providing_organisation_reference: "GB-GOV-13") | ||
end | ||
|
||
Forecast.unscoped.where(parent_activity_id: activity.id, providing_organisation_reference: "GB-GOV-26").each do |forecast| | ||
forecast.update(providing_organisation_reference: "GB-GOV-13") | ||
end | ||
end | ||
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