Skip to content

Commit

Permalink
Merge pull request #2320 from UKGovernmentBEIS/3006-change-continuing…
Browse files Browse the repository at this point in the history
…-activities

(3007) Change transparency identifier
  • Loading branch information
CristinaRO committed Jan 19, 2024
2 parents 8ba7b20 + 0004bbb commit 1673bff
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Exclude health check requests from host authorisation
- Remove the feature flag for ODA bulk upload
- Change the transparency identifier and names for the DSIT organisations (DSIT and DSIT Finance)
- Update the transparency identifier of activities that are continuing under DSIT, and the providing org reference of their actuals and forecasts

## Release 142 - 2024-01-16

Expand Down
70 changes: 70 additions & 0 deletions db/migrate/20240115183402_change_transparency_identifier.rb
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
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_01_11_133813) do
ActiveRecord::Schema.define(version: 2024_01_15_183402) do

# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
Expand Down

0 comments on commit 1673bff

Please sign in to comment.