diff --git a/app/models/csv_variable_definition.rb b/app/models/csv_variable_definition.rb new file mode 100644 index 000000000..a1417788e --- /dev/null +++ b/app/models/csv_variable_definition.rb @@ -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 diff --git a/db/migrate/20240726152326_create_csv_variable_definitions.rb b/db/migrate/20240726152326_create_csv_variable_definitions.rb new file mode 100644 index 000000000..d194b6dec --- /dev/null +++ b/db/migrate/20240726152326_create_csv_variable_definitions.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 50073d2d6..8752664b1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_07_15_082338) do +ActiveRecord::Schema[7.0].define(version: 2024_07_26_152326) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -46,6 +46,20 @@ ActiveRecord::Schema[7.0].define(version: 2024_07_15_082338) do t.index ["user_id"], name: "index_bulk_uploads_on_user_id" end + create_table "csv_variable_definitions", force: :cascade 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.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.check_constraint "log_type::text = ANY (ARRAY['lettings'::character varying, 'sales'::character varying]::text[])", name: "log_type_check" + t.check_constraint "user_type::text = ANY (ARRAY['user'::character varying, 'support'::character varying]::text[])", name: "user_type_check" + t.check_constraint "year >= 2000 AND year <= 2099", name: "year_check" + end + create_table "data_protection_confirmations", force: :cascade do |t| t.bigint "organisation_id" t.bigint "data_protection_officer_id"