Sha256: c9934c7b7a49a87c0e3d5213889be868418e479ca9742b77cf998c0b9ecc810e

Contents?: true

Size: 1.2 KB

Versions: 161

Compression:

Stored size: 1.2 KB

Contents

class RenameAccessPlansToAccessPlanTypes < ActiveRecord::Migration[5.0]
  def change
    remove_column :access_profiles, :plan_id
    remove_column :access_profiles, :planned_on

    rename_table :access_plans, :access_plan_types

    create_table :access_plans do |t|
      t.integer :plan_type_id, null: false, index: true
      t.text :notes
      t.integer :patient_id, null: false, index: true
      t.integer :decided_by_id, index: true
      t.integer :updated_by_id, null: false, index: true
      t.integer :created_by_id, null: false, index: true
      t.datetime :terminated_at, index: true
      t.timestamps null: false
    end

    add_foreign_key :access_plans, :access_plan_types, column: :plan_type_id
    add_foreign_key :access_plans, :patients, column: :patient_id
    add_foreign_key :access_plans, :users, column: :decided_by_id
    add_foreign_key :access_plans, :users, column: :created_by_id
    add_foreign_key :access_plans, :users, column: :updated_by_id

    # There can only ever be one un-terminated plan per user - is the current one
    connection.execute(
      "CREATE UNIQUE INDEX access_plan_uniqueness ON access_plans
      (patient_id, COALESCE(terminated_at, '1970-01-01'));"
    )
  end
end

Version data entries

161 entries across 161 versions & 1 rubygems

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