Skip to content

Commit 826cf79

Browse files
committed
Add migration to backfill patient IDs in notify log entries
Jira-Issue: MAV-5062
1 parent baae3e8 commit 826cf79

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
class BackfillPatientIdOnNotifyLogEntries < ActiveRecord::Migration[8.1]
4+
def up
5+
migration = self.class.name
6+
started_at = Time.zone.now
7+
8+
scope = NotifyLogEntry.where(patient_id: nil).where.not(consent_form_id: nil)
9+
10+
Rails.logger.info(event: "data_migration_start", migration:, total_records: scope.count)
11+
12+
records_updated =
13+
scope
14+
.joins(
15+
"INNER JOIN consents ON consents.consent_form_id = notify_log_entries.consent_form_id"
16+
)
17+
.update_all("patient_id = consents.patient_id")
18+
19+
duration_minutes = ((Time.zone.now - started_at) / 60.0).round
20+
21+
Rails.logger.info(
22+
event: "data_migration_finish",
23+
migration:,
24+
duration_minutes:,
25+
records_updated:
26+
)
27+
end
28+
29+
def down
30+
raise ActiveRecord::IrreversibleMigration
31+
end
32+
end

db/data_schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
DataMigrate::Data.define(version: 2026_03_05_165603)
1+
DataMigrate::Data.define(version: 2026_03_12_182158)

0 commit comments

Comments
 (0)