Skip to content

Revert "Update migration script and SpineOpt DB version" #1223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/6_unit_system.json
Original file line number Diff line number Diff line change
Expand Up @@ -83185,7 +83185,7 @@
[
"settings",
"version",
20,
16,
null,
"Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."
],
Expand Down
2 changes: 1 addition & 1 deletion examples/capacity_planning.json
Original file line number Diff line number Diff line change
Expand Up @@ -3497,7 +3497,7 @@
[
"settings",
"version",
20,
16,
null,
"Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3320,7 +3320,7 @@
[
"settings",
"version",
20,
16,
null,
"Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3392,7 +3392,7 @@
[
"settings",
"version",
20,
16,
null,
"Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3313,7 +3313,7 @@
[
"settings",
"version",
20,
16,
null,
"Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."
],
Expand Down
2 changes: 1 addition & 1 deletion examples/reserves.json
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@
[
"settings",
"version",
20,
16,
null,
"Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."
],
Expand Down
2 changes: 1 addition & 1 deletion examples/rolling_horizon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@
[
"settings",
"version",
20,
16,
null,
"Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."
],
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_system.json
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@
[
"settings",
"version",
20,
16,
null,
"Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."
],
Expand Down
2 changes: 1 addition & 1 deletion examples/stochastic.json
Original file line number Diff line number Diff line change
Expand Up @@ -3327,7 +3327,7 @@
[
"settings",
"version",
20,
16,
null,
"Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."
],
Expand Down
2 changes: 1 addition & 1 deletion examples/unit_commitment.json
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@
[
"settings",
"version",
20,
16,
null,
"Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."
],
Expand Down
24 changes: 2 additions & 22 deletions src/data_structure/migration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,15 @@
include("versions/add_model_algorithm.jl")
include("versions/rename_lifetime_to_tech_lifetime.jl")
include("versions/translate_heatrate_parameters.jl")
include("versions/translate_use_economic_representation__use_milestone_years.jl")

function add_units_out_of_service_and_min_capacity_margin(db_url, log_level)
# No changes, just make sure we load the newest template
return true
true

Check warning on line 47 in src/data_structure/migration.jl

View check run for this annotation

Codecov / codecov/patch

src/data_structure/migration.jl#L47

Added line #L47 was not covered by tests
end

function add_stage_output(db_url, log_level)
# No changes, just make sure we load the newest template
return true
end

function add_node_availability_factor(db_url, log_level)
# No changes, just make sure we load the newest template
return true
end

function add_node_state_min_factor(db_url, log_level)
# No changes, just make sure we load the newest template
return true
end

function add_connection_min_factor(db_url, log_level)
# No changes, just make sure we load the newest template
return true
true

Check warning on line 52 in src/data_structure/migration.jl

View check run for this annotation

Codecov / codecov/patch

src/data_structure/migration.jl#L52

Added line #L52 was not covered by tests
end

_upgrade_functions = [
Expand All @@ -84,10 +68,6 @@
rename_lifetime_to_tech_lifetime,
translate_heatrate_parameters,
add_stage_output,
add_node_availability_factor,
add_node_state_min_factor,
add_connection_min_factor,
translate_use_economic_representation__use_milestone_years,
]

"""
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion templates/spineopt_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
["output", "output_resolution", null, null, "Temporal resolution of the output variables associated with this `output`."],
["output", "output_type",null,"output_type_list","Type of this `output`."],
["report", "output_db_url", null, null, "Database url for SpineOpt output."],
["settings", "version", 20, null, "Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."],
["settings", "version", 16, null, "Current version of the SpineOpt data structure. Modify it at your own risk (but please don't)."],
["stage", "stage_scenario", null, null, "The scenario that this `stage` should run (EXPERIMENTAL)."],
["temporal_block", "block_end", null, null, "The end time for the `temporal_block`. Can be given either as a `DateTime` for a static end point, or as a `Duration` for an end point relative to the start of the current optimization."],
["temporal_block", "block_start", null, null, "The start time for the `temporal_block`. Can be given either as a `DateTime` for a static start point, or as a `Duration` for an start point relative to the start of the current optimization."],
Expand Down
84 changes: 0 additions & 84 deletions test/data_structure/migration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,88 +335,6 @@ function _test_translate_heatrate_parameters()
end
end

function _test_translate_use_economic_representation__use_milestone_years_setup()
url_in = "sqlite://"
data = Dict(
:object_classes => ["model",],
:objects => [
("model", "instance"),
],
:parameter_value_lists => [("boolean_value_list", true), ("boolean_value_list", false)],
:object_parameters => [
("model", "use_economic_representation", false, "boolean_value_list"),
("model", "use_milestone_years", false, "boolean_value_list"),
],
)
_load_test_data_without_template(url_in, data)
url_in
end

function _test_translate_use_economic_representation__use_milestone_years()
_options = (nothing, false, true)
cases = collect(Iterators.product(_options, _options))

for (use_economic_representation, use_milestone_years) in cases
@testset "translate_use_economic_representation__use_milestone_years:
use_economic_representation = $use_economic_representation,
use_milestone_years = $use_milestone_years" begin
url = _test_translate_use_economic_representation__use_milestone_years_setup()
object_parameter_values = [
["model", "instance", "use_economic_representation", use_economic_representation],
["model", "instance", "use_milestone_years", use_milestone_years]
]
SpineInterface.import_data(
url;
object_parameter_values=object_parameter_values,
)

Y = Module()
using_spinedb(url, Y)
@test SpineOpt.translate_use_economic_representation__use_milestone_years(url, 0) === true
run_request(
url, "call_method", ("commit_session", "translate_use_economic_representation__use_milestone_years")
)

_check = run_request(
url,
"query",
("list_value_sq", "parameter_value_list_sq"),
)
@show collect(_check)

old_parameter_names = [:use_economic_representation, :use_milestone_years]
new_parameter_name = :multiyear_economic_discounting

using_spinedb(url, Y)

all_parameter_names = [x.name for x in parameters(Y)]
@test isempty(intersect(all_parameter_names, old_parameter_names))
@test new_parameter_name in all_parameter_names

if isnothing(use_economic_representation) || !use_economic_representation
@test isnothing(Y.multiyear_economic_discounting(model=Y.model(:instance)))
else
if isnothing(use_milestone_years) || !use_milestone_years
@test Y.multiyear_economic_discounting(model=Y.model(:instance)) == :consecutive_years
elseif use_milestone_years == true
@test Y.multiyear_economic_discounting(model=Y.model(:instance)) == :milestone_years
end
end
end
end
end

function _test_dummy_migrations_functions()
url_in = "sqlite://"
@testset "dummy_migrations_functions" begin
@test SpineOpt.add_units_out_of_service_and_min_capacity_margin(url_in,0)
@test SpineOpt.add_stage_output(url_in,0)
@test SpineOpt.add_node_availability_factor(url_in,0)
@test SpineOpt.add_node_state_min_factor(url_in,0)
@test SpineOpt.add_connection_min_factor(url_in,0)
end
end

@testset "migration scripts" begin
_test_rename_unit_constraint_to_user_constraint()
_test_move_connection_flow_cost()
Expand All @@ -427,6 +345,4 @@ end
_test_add_model_algorithm()
_test_rename_lifetime_to_tech_lifetime()
_test_translate_heatrate_parameters()
_test_translate_use_economic_representation__use_milestone_years()
_test_dummy_migrations_functions()
end
Loading