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 5af03a7 commit 3305f72
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 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,24 @@
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

change_column_null :claims, :started_at, false
end

def down
Claim.update_all(started_at: nil)
end
end
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -111,7 +111,7 @@
t.text "onelogin_idv_first_name"
t.text "onelogin_idv_last_name"
t.date "onelogin_idv_date_of_birth"
t.datetime "started_at", precision: nil
t.datetime "started_at", precision: nil, null: false
t.index ["academic_year"], name: "index_claims_on_academic_year"
t.index ["created_at"], name: "index_claims_on_created_at"
t.index ["eligibility_type", "eligibility_id"], name: "index_claims_on_eligibility_type_and_eligibility_id"
Expand Down

0 comments on commit 3305f72

Please sign in to comment.