Sha256: dcddfe551de296e540d47553e2a7b453a574a5596aefc59952609b4214ee2a91

Contents?: true

Size: 1.18 KB

Versions: 86

Compression:

Stored size: 1.18 KB

Contents

class AddLastChangeDateToPatientPractices < ActiveRecord::Migration[5.2]
  def change
    add_column :patient_practices, :last_change_date, :date

    # Here we are moving away from using a deleted_at/acts_as_paranoid approach to hiding practices
    # to just having an #active boolean flag - this more closely emulates the output of the NHS
    # Organisation Data Service (ODS) API which returns Status = Active ot Status = Inactive.
    # Because we are doing some data migration here also, we need to manually handle the rollback.
    reversible do |direction|
      direction.up do
        add_column :patient_practices, :active, :boolean, default: true, index: true
        connection.execute(
          "update renalware.patient_practices set active = false where deleted_at is not null;"
        )
        remove_column :patient_practices, :deleted_at, :datetime
      end
      direction.down do
        add_column :patient_practices, :deleted_at, :datetime, index: true
        connection.execute(
          "update renalware.patient_practices set deleted_at = '2000-01-01' where active = false;"
        )
        remove_column :patient_practices, :active, :boolean
      end
    end
  end
end

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
renalware-core-2.1.1 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.1.0 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.167 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.166 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.165 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.164 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.163 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.162 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.161 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.160 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.159 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.158 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.157 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.156 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.155 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.153 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.152 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.151 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.149 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb
renalware-core-2.0.148 db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb