3 changed files with 40 additions and 1 deletions
@ -0,0 +1,8 @@ |
|||||||
|
class CsvVariableDefinition < ApplicationRecord |
||||||
|
validates :variable, presence: true |
||||||
|
validates :definition, presence: true |
||||||
|
validates :log_type, presence: true, inclusion: { in: %w[lettings sales] } |
||||||
|
validates :user_type, presence: true, inclusion: { in: %w[user support] } |
||||||
|
validates :year, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 2000, less_than_or_equal_to: 2099 } |
||||||
|
attribute :last_accessed, :datetime |
||||||
|
end |
||||||
@ -0,0 +1,17 @@ |
|||||||
|
class CreateCsvVariableDefinitions < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
create_table :csv_variable_definitions do |t| |
||||||
|
t.string :variable, null: false |
||||||
|
t.string :definition, null: false |
||||||
|
t.string :log_type, null: false |
||||||
|
t.string :user_type, null: false |
||||||
|
t.integer :year, null: false |
||||||
|
t.datetime :last_accessed |
||||||
|
t.timestamps |
||||||
|
end |
||||||
|
|
||||||
|
add_check_constraint :csv_variable_definitions, "user_type IN ('user', 'support')", name: "user_type_check" |
||||||
|
add_check_constraint :csv_variable_definitions, "log_type IN ('lettings', 'sales')", name: "log_type_check" |
||||||
|
add_check_constraint :csv_variable_definitions, "year BETWEEN 2000 AND 2099", name: "year_check" |
||||||
|
end |
||||||
|
end |
||||||
Loading…
Reference in new issue