From e281157bd7e2b0228d934fd1a249fe1b06154b8a Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Tue, 24 Sep 2024 11:23:42 +0100 Subject: [PATCH] Back fill started at If the claim has a journey session we try and set the `started_at` to that, if it doesn't have a journey session we'll just use the `created_at` timestamp, which for claims pre the introduction of journey sessions will be the started at time. --- ...40924095435_back_fill_claims_started_at.rb | 22 +++++++++++++++++++ db/schema.rb | 2 +- spec/factories/claims.rb | 2 ++ ...qt_in_academic_year_after_itt_form_spec.rb | 5 ++++- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20240924095435_back_fill_claims_started_at.rb diff --git a/db/migrate/20240924095435_back_fill_claims_started_at.rb b/db/migrate/20240924095435_back_fill_claims_started_at.rb new file mode 100644 index 0000000000..ec06356841 --- /dev/null +++ b/db/migrate/20240924095435_back_fill_claims_started_at.rb @@ -0,0 +1,22 @@ +class BackFillClaimsStartedAt < ActiveRecord::Migration[7.0] + def up + execute <<-SQL + UPDATE claims + SET started_at = journeys_sessions.created_at + FROM journeys_sessions + WHERE claims.journeys_session_id = journeys_sessions.id + AND claims.started_at IS NULL + SQL + + execute <<-SQL + UPDATE claims + SET started_at = created_at + WHERE journeys_session_id IS NULL + AND claims.started_at IS NULL + SQL + end + + def down + Claim.update_all(started_at: nil) + end +end diff --git a/db/schema.rb b/db/schema.rb index e7efeab458..34f57b1871 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_09_24_091408) do +ActiveRecord::Schema[7.0].define(version: 2024_09_24_095435) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "pg_trgm" diff --git a/spec/factories/claims.rb b/spec/factories/claims.rb index becd4f94d1..7e2f07646d 100644 --- a/spec/factories/claims.rb +++ b/spec/factories/claims.rb @@ -4,6 +4,8 @@ sequence(:national_insurance_number, 100000) { |n| "QQ#{n}C" } factory :claim do + started_at { Time.zone.now } + transient do policy { Policies::StudentLoans } eligibility_factory { :"#{policy.to_s.underscore}_eligibility" } diff --git a/spec/forms/journeys/additional_payments_for_teaching/nqt_in_academic_year_after_itt_form_spec.rb b/spec/forms/journeys/additional_payments_for_teaching/nqt_in_academic_year_after_itt_form_spec.rb index e5895dc716..f85c899f95 100644 --- a/spec/forms/journeys/additional_payments_for_teaching/nqt_in_academic_year_after_itt_form_spec.rb +++ b/spec/forms/journeys/additional_payments_for_teaching/nqt_in_academic_year_after_itt_form_spec.rb @@ -131,7 +131,10 @@ { details_check: true, logged_in_with_tid: true - }.merge(attributes_for(:claim, :with_dqt_teacher_status)) + }.merge( + attributes_for(:claim, :with_dqt_teacher_status) + .except(:started_at) + ) end it "sets the induction as complete" do