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.0.104 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.103 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.102 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.101 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.100 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.99 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.98 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.97 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.96 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.95 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.94 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.93 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.92 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.91 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.90 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.89 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.88 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.87 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.86 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb
renalware-core-2.0.85 db/migrate/20170707110155_rename_access_plans_to_access_plan_types.rb