Browse Source

Create CSV Variable Definitions model

pull/2539/head
Manny Dinssa 2 years ago
parent
commit
060f018026
  1. 8
      app/models/csv_variable_definition.rb
  2. 17
      db/migrate/20240726152326_create_csv_variable_definitions.rb
  3. 16
      db/schema.rb

8
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

17
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

16
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"

Loading…
Cancel
Save