Skip to content

Commit

Permalink
data migration: clear ICDDRB prescription_drugs (#5389)
Browse files Browse the repository at this point in the history
**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.
  • Loading branch information
tfidfwastaken authored Feb 20, 2024
1 parent 7a5e46f commit e35fae4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions db/data/20240215112358_destroy_icddrb_prescription_drugs.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e35fae4

Please sign in to comment.