Sha256: ad75fca056b395d1ce15e5193e06f6f1b2b3dd1bed2f5b9d959fbccf2f83765d
Contents?: true
Size: 969 Bytes
Versions: 13
Compression:
Stored size: 969 Bytes
Contents
class AddBMIToClinicVisits < ActiveRecord::Migration[5.2] def change within_renalware_schema do add_column( :clinic_visits, :bmi, :decimal, precision: 10, scale: 1, null: true, comment: "Body Mass Index calculated using a before_save when the clinic visit is updated" ) reversible do |direction| direction.up do # Update the bmi for existing clinic visits, but restrict to avoid generating a # non-sense value in case height or weight were entered incorrectly. # NB: height is in metres and weight in kg connection.execute( "update renalware.clinic_visits "\ "set bmi = round(((weight / height)::decimal / height::decimal), 1) "\ "where height > 0 and height < 3 and weight > 0 and weight < 500;" ) end direction.down do # noop end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems