diff --git a/app/models/saved_scenario.rb b/app/models/saved_scenario.rb index 816a1ee..b787c78 100644 --- a/app/models/saved_scenario.rb +++ b/app/models/saved_scenario.rb @@ -14,6 +14,9 @@ class SavedScenario < ApplicationRecord validates :title, presence: true validates :end_year, presence: true validates :area_code, presence: true + validates :version, presence: true, inclusion: { + in: Version.all + } serialize :scenario_id_history, coder: YAML, type: Array end diff --git a/app/models/version.rb b/app/models/version.rb new file mode 100644 index 0000000..d3a3bd3 --- /dev/null +++ b/app/models/version.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# A valid version of the ETM +class Version + LIST = %i[ + latest + ].freeze + + # All available versions. Uses ActiveRecord syntax 'all' to + # make future porting to db easier + def self.all + LIST + end +end diff --git a/db/migrate/20241014102534_create_saved_scenarios.rb b/db/migrate/20241014102534_create_saved_scenarios.rb index 2fbfc0b..7cee9b7 100644 --- a/db/migrate/20241014102534_create_saved_scenarios.rb +++ b/db/migrate/20241014102534_create_saved_scenarios.rb @@ -5,6 +5,7 @@ def change t.text :scenario_id_history t.string :title, null: false t.text :description + t.string :version, default: 'latest' t.string :area_code, null: false t.integer :end_year, null: false t.boolean :private, default: false diff --git a/db/schema.rb b/db/schema.rb index 9321b35..01fb7b9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -16,6 +16,7 @@ t.text "scenario_id_history" t.string "title", null: false t.text "description" + t.string "version", default: "latest" t.string "area_code", null: false t.integer "end_year", null: false t.boolean "private", default: false