|
| 1 | +require 'etengine/scenario_migration' |
| 2 | + |
| 3 | +class UpdateSolarthermalBuildings < ActiveRecord::Migration[7.1] |
| 4 | + include ETEngine::ScenarioMigration |
| 5 | + |
| 6 | + def up |
| 7 | + migrate_scenarios do |scenario| |
| 8 | + # Insert your code here which will migrate each scenario, and delete this |
| 9 | + # documentation comment. |
| 10 | + # |
| 11 | + |
| 12 | + if scenario.user_values.key?('buildings_space_heater_solar_thermal_share') |
| 13 | + scenario.user_values['buildings_space_heater_solar_thermal_share'] *= 0.13 |
| 14 | + end |
| 15 | + # |
| 16 | + # If you need to reference data from Atlas, be sure to check that the |
| 17 | + # dataset used by the scenario still exists: |
| 18 | + # |
| 19 | + # next unless Atlas::Dataset.exists?(scenario.area_code) |
| 20 | + # |
| 21 | + # Scenarios will be automatically saved if changes were made. |
| 22 | + # |
| 23 | + # ### Candidate scenarios |
| 24 | + # |
| 25 | + # By default, all `keep_updated` scenarios are migrated, along with any |
| 26 | + # other scenarios modified in the last month. You may supply a |
| 27 | + # custom cutoff date for migrating unprotected scenarios with the `since` |
| 28 | + # keyword argument. |
| 29 | + # |
| 30 | + # For example, to migrate scenarios up to three months old whose |
| 31 | + # `keep_updated` attribute is false: |
| 32 | + # |
| 33 | + # migrate_scenarios(since: 3.months.ago) do |scenario| |
| 34 | + # # ... |
| 35 | + # end |
| 36 | + # |
| 37 | + # ### Errors |
| 38 | + # |
| 39 | + # An error will be raised if no scenarios were migrated, as it is often |
| 40 | + # unexpected for a migration to result in no changes. If you wish to |
| 41 | + # disable this behaviour, supply `raise_on_no_changes: false` to |
| 42 | + # `migrate_scenarios`. For example: |
| 43 | + # |
| 44 | + # migrate_scenarios(raise_on_no_changes: false) do |scenario| |
| 45 | + # # ... |
| 46 | + # end |
| 47 | + end |
| 48 | + end |
| 49 | +end |
0 commit comments