Browse Source

Introduce LaSalesRange model and data

Import using the new rake task which mimics La Rent Range import from csv

rake data_import:sales_ranges\[2022,"/Users/mohseeadmin/development/submit-social-housing-lettings-and-sales-data/config/sales_range_data/2022.csv"\]
"Created/updated 1328 LA Sales Range records"
CLDC-858-update-sales-property-information
Mo Seedat 2 years ago
parent
commit
7a5fe3bc44
  1. 2
      app/models/la_sales_range.rb
  2. 1329
      config/sales_range_data/2022.csv
  3. 15
      db/migrate/20221016203810_create_la_sales_ranges.rb
  4. 14
      db/schema.rb
  5. 27
      lib/tasks/sales_ranges.rake

2
app/models/la_sales_range.rb

@ -0,0 +1,2 @@
class LaSalesRange < ApplicationRecord
end

1329
config/sales_range_data/2022.csv

File diff suppressed because it is too large Load Diff

15
db/migrate/20221016203810_create_la_sales_ranges.rb

@ -0,0 +1,15 @@
class CreateLaSalesRanges < ActiveRecord::Migration[7.0]
def change
create_table :la_sales_ranges do |t|
t.string :la
t.string :la_name
t.integer :beds
t.integer :soft_min, null: false
t.integer :soft_max, null: false
t.integer :start_year, null: false
t.index %i[start_year beds la], unique: true
t.timestamps
end
end
end

14
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_10_07_093606) do ActiveRecord::Schema[7.0].define(version: 2022_10_16_203810) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -42,6 +42,18 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_07_093606) do
t.index ["start_year", "lettype", "beds", "la"], name: "index_la_rent_ranges_on_start_year_and_lettype_and_beds_and_la", unique: true t.index ["start_year", "lettype", "beds", "la"], name: "index_la_rent_ranges_on_start_year_and_lettype_and_beds_and_la", unique: true
end end
create_table "la_sales_ranges", force: :cascade do |t|
t.string "la"
t.string "la_name"
t.integer "beds"
t.integer "soft_min", null: false
t.integer "soft_max", null: false
t.integer "start_year", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["start_year", "beds", "la"], name: "index_la_sales_ranges_on_start_year_and_beds_and_la", unique: true
end
create_table "legacy_users", force: :cascade do |t| create_table "legacy_users", force: :cascade do |t|
t.string "old_user_id" t.string "old_user_id"
t.integer "user_id" t.integer "user_id"

27
lib/tasks/sales_ranges.rake

@ -0,0 +1,27 @@
require "csv"
namespace :data_import do
desc "Import annual sales range data"
task :sales_ranges, %i[start_year path] => :environment do |_task, args|
start_year = args[:start_year]
path = args[:path]
count = 0
raise "Usage: rake data_import:sales_ranges[start_year,'path/to/csv_file']" if path.blank? || start_year.blank?
CSV.foreach(path, headers: true) do |row|
LaSalesRange.upsert(
{
beds: row["beds"],
start_year: start_year,
la: row["la"],
soft_min: row["soft_min"],
soft_max: row["soft_max"]
},
unique_by: %i[start_year beds la],
)
count += 1
end
pp "Created/updated #{count} LA Sales Range records" unless Rails.env.test?
end
end
Loading…
Cancel
Save