Skip to content

Commit ec002c0

Browse files
authored
Merge pull request #6640 from NHSDigital/alistair/patient-cascade-on-delete-validate
Validate new `Patient` foreign key relationships
2 parents ed5431f + 2b75eed commit ec002c0

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"
@@ -1152,7 +1152,7 @@
11521152
add_foreign_key "notes", "users", column: "created_by_user_id"
11531153
add_foreign_key "notify_log_entries", "consent_forms"
11541154
add_foreign_key "notify_log_entries", "parents", on_delete: :nullify
1155-
add_foreign_key "notify_log_entries", "patients", on_delete: :cascade, validate: false
1155+
add_foreign_key "notify_log_entries", "patients", on_delete: :cascade
11561156
add_foreign_key "notify_log_entries", "users", column: "sent_by_user_id"
11571157
add_foreign_key "notify_log_entry_programmes", "notify_log_entries", on_delete: :cascade
11581158
add_foreign_key "parent_relationships", "parents"
@@ -1161,10 +1161,10 @@
11611161
add_foreign_key "patient_changesets", "patients"
11621162
add_foreign_key "patient_locations", "locations"
11631163
add_foreign_key "patient_locations", "patients"
1164-
add_foreign_key "patient_merge_log_entries", "patients", on_delete: :cascade, validate: false
1164+
add_foreign_key "patient_merge_log_entries", "patients", on_delete: :cascade
11651165
add_foreign_key "patient_merge_log_entries", "users"
11661166
add_foreign_key "patient_programme_statuses", "patients", on_delete: :cascade
1167-
add_foreign_key "patient_programme_vaccinations_searches", "patients", on_delete: :cascade, validate: false
1167+
add_foreign_key "patient_programme_vaccinations_searches", "patients", on_delete: :cascade
11681168
add_foreign_key "patient_registration_statuses", "patients", on_delete: :cascade
11691169
add_foreign_key "patient_registration_statuses", "sessions", on_delete: :cascade
11701170
add_foreign_key "patient_specific_directions", "patients"
@@ -1175,13 +1175,13 @@
11751175
add_foreign_key "patient_teams", "teams", on_delete: :cascade
11761176
add_foreign_key "patients", "locations", column: "gp_practice_id"
11771177
add_foreign_key "patients", "locations", column: "school_id"
1178-
add_foreign_key "pds_search_results", "patients", on_delete: :cascade, validate: false
1178+
add_foreign_key "pds_search_results", "patients", on_delete: :cascade
11791179
add_foreign_key "pre_screenings", "locations"
11801180
add_foreign_key "pre_screenings", "patients"
11811181
add_foreign_key "pre_screenings", "users", column: "performed_by_user_id"
11821182
add_foreign_key "reporting_api_one_time_tokens", "users"
11831183
add_foreign_key "school_move_log_entries", "locations", column: "school_id"
1184-
add_foreign_key "school_move_log_entries", "patients", on_delete: :cascade, validate: false
1184+
add_foreign_key "school_move_log_entries", "patients", on_delete: :cascade
11851185
add_foreign_key "school_move_log_entries", "teams"
11861186
add_foreign_key "school_move_log_entries", "users"
11871187
add_foreign_key "school_moves", "locations", column: "school_id"

0 commit comments

Comments
 (0)