From e35fae428d3efb57b26bce751e247a716f3e2fe4 Mon Sep 17 00:00:00 2001 From: Atharva Raykar <24277692+tfidfwastaken@users.noreply.github.com> Date: Tue, 20 Feb 2024 12:51:17 +0530 Subject: [PATCH] data migration: clear ICDDRB prescription_drugs (#5389) **Story card:** [sc-12002] ## How do I know this is correct? I converted the activerecord query on rails console like this: ```ruby destroyed_drugs = PrescriptionDrug .joins(facility: {facility_group: :organization}) .where(organization: {id: ORG_ID}) .to_sql ``` I pasted the resulting SQL output on Metabase BD and inspected the result to ensure that I would be deleting the right thing. --- ...12358_destroy_icddrb_prescription_drugs.rb | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 db/data/20240215112358_destroy_icddrb_prescription_drugs.rb diff --git a/db/data/20240215112358_destroy_icddrb_prescription_drugs.rb b/db/data/20240215112358_destroy_icddrb_prescription_drugs.rb new file mode 100644 index 0000000000..4423d9d19a --- /dev/null +++ b/db/data/20240215112358_destroy_icddrb_prescription_drugs.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class DestroyIcddrbPrescriptionDrugs < ActiveRecord::Migration[6.1] + ORG_ID = "1bb836eb-9a0b-4646-96ad-7342b53a9155" + + def up + unless CountryConfig.current_country?("Bangladesh") && SimpleServer.env.production? + return print "DestroyIcddrbPrescriptionDrugs is only for production Bangladesh" + end + + destroyed_drugs = PrescriptionDrug + .joins(facility: {facility_group: :organization}) + .where(organization: {id: ORG_ID}) + .destroy_all + + puts "deleted:\n #{destroyed_drugs.size} drugs" + end + + def down + puts "This migration cannot be reversed." + end +end