Skip to content

Commit

Permalink
Introduce static version model
Browse files Browse the repository at this point in the history
  • Loading branch information
noracato committed Oct 17, 2024
1 parent 8c924af commit c45540d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/models/saved_scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions app/models/version.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions db/migrate/20241014102534_create_saved_scenarios.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c45540d

Please sign in to comment.