Skip to content

Commit

Permalink
Back fill started at
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjlynch committed Sep 24, 2024
1 parent 08eef0f commit e281157
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
22 changes: 22 additions & 0 deletions db/migrate/20240924095435_back_fill_claims_started_at.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e281157

Please sign in to comment.