Skip to content

Commit 2b75eed

Browse files
Validate new Patient foreign key relationships
After adding "cascade on delete" to these `Patient` FK relationships, we need to validate them. We can't do this as part of the same migration because it's likely to cause a long table lock, which is unacceptable in production. Hence, this needs to be included in the subsequent release. Jira-Issue: MAV-7065
1 parent 0d81782 commit 2b75eed

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
class ValidatePatientForeignKeys < ActiveRecord::Migration[8.1]
4+
TABLES_TO_CASCADE = %w[
5+
notify_log_entries
6+
school_move_log_entries
7+
patient_merge_log_entries
8+
pds_search_results
9+
patient_programme_vaccinations_searches
10+
].freeze
11+
12+
def change
13+
TABLES_TO_CASCADE.each { |table| validate_foreign_key table, "patients" }
14+
end
15+
end

db/schema.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.1].define(version: 2026_04_20_101139) do
13+
ActiveRecord::Schema[8.1].define(version: 2026_04_20_122440) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_catalog.plpgsql"
1616
enable_extension "pg_trgm"
@@ -1150,7 +1150,7 @@
11501150
add_foreign_key "notes", "users", column: "created_by_user_id"
11511151
add_foreign_key "notify_log_entries", "consent_forms"
11521152
add_foreign_key "notify_log_entries", "parents", on_delete: :nullify
1153-
add_foreign_key "notify_log_entries", "patients", on_delete: :cascade, validate: false
1153+
add_foreign_key "notify_log_entries", "patients", on_delete: :cascade
11541154
add_foreign_key "notify_log_entries", "users", column: "sent_by_user_id"
11551155
add_foreign_key "notify_log_entry_programmes", "notify_log_entries", on_delete: :cascade
11561156
add_foreign_key "parent_relationships", "parents"
@@ -1159,10 +1159,10 @@
11591159
add_foreign_key "patient_changesets", "patients"
11601160
add_foreign_key "patient_locations", "locations"
11611161
add_foreign_key "patient_locations", "patients"
1162-
add_foreign_key "patient_merge_log_entries", "patients", on_delete: :cascade, validate: false
1162+
add_foreign_key "patient_merge_log_entries", "patients", on_delete: :cascade
11631163
add_foreign_key "patient_merge_log_entries", "users"
11641164
add_foreign_key "patient_programme_statuses", "patients", on_delete: :cascade
1165-
add_foreign_key "patient_programme_vaccinations_searches", "patients", on_delete: :cascade, validate: false
1165+
add_foreign_key "patient_programme_vaccinations_searches", "patients", on_delete: :cascade
11661166
add_foreign_key "patient_registration_statuses", "patients", on_delete: :cascade
11671167
add_foreign_key "patient_registration_statuses", "sessions", on_delete: :cascade
11681168
add_foreign_key "patient_specific_directions", "patients"
@@ -1173,13 +1173,13 @@
11731173
add_foreign_key "patient_teams", "teams", on_delete: :cascade
11741174
add_foreign_key "patients", "locations", column: "gp_practice_id"
11751175
add_foreign_key "patients", "locations", column: "school_id"
1176-
add_foreign_key "pds_search_results", "patients", on_delete: :cascade, validate: false
1176+
add_foreign_key "pds_search_results", "patients", on_delete: :cascade
11771177
add_foreign_key "pre_screenings", "locations"
11781178
add_foreign_key "pre_screenings", "patients"
11791179
add_foreign_key "pre_screenings", "users", column: "performed_by_user_id"
11801180
add_foreign_key "reporting_api_one_time_tokens", "users"
11811181
add_foreign_key "school_move_log_entries", "locations", column: "school_id"
1182-
add_foreign_key "school_move_log_entries", "patients", on_delete: :cascade, validate: false
1182+
add_foreign_key "school_move_log_entries", "patients", on_delete: :cascade
11831183
add_foreign_key "school_move_log_entries", "teams"
11841184
add_foreign_key "school_move_log_entries", "users"
11851185
add_foreign_key "school_moves", "locations", column: "school_id"

0 commit comments

Comments
 (0)