Sha256: dd8903f1b35a6c371a84f3f4adddb7e06527900d39cf971fec61241ff941a1eb

Contents?: true

Size: 1.42 KB

Versions: 171

Compression:

Stored size: 1.42 KB

Contents

class CreateHDDiarySlots < ActiveRecord::Migration[5.1]
  def change
    create_table :hd_diary_slots do |t|
      t.integer :diary_id, null: false, index: true
      t.integer :station_id, null: false, index: true
      t.integer :day_of_week, null: false, index: true
      t.integer :diurnal_period_code_id, null: false, index: true
      t.references :patient, null: false, foreign_key: true, index: true
      t.integer :updated_by_id, null: false, index: true
      t.integer :created_by_id, null: false, index: true
      t.datetime :deleted_at, index: true
      t.timestamps null: false
    end

    # Add CHECK constraint to ensure week and year are in valid ranges
    reversible do |direction|
      direction.up do
        execute <<-SQL
          ALTER TABLE hd_diary_slots
            ADD CONSTRAINT day_of_week_in_valid_range CHECK (day_of_week >= 1 AND day_of_week <= 7);
        SQL
      end
      direction.down do
        execute <<-SQL
          ALTER TABLE hd_diary_slots DROP CONSTRAINT day_of_week_in_valid_range;
        SQL
      end
    end

    add_foreign_key :hd_diary_slots, :hd_stations, column: :station_id
    add_foreign_key :hd_diary_slots, :hd_diaries, column: :diary_id
    add_foreign_key :hd_diary_slots, :users, column: :created_by_id
    add_foreign_key :hd_diary_slots, :users, column: :updated_by_id
    add_foreign_key :hd_diary_slots, :hd_diurnal_period_codes, column: :diurnal_period_code_id
  end
end

Version data entries

171 entries across 171 versions & 1 rubygems

Version Path
renalware-core-2.0.147 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.146 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.145 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.144 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.143 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.142 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.141 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.140 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.139 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.138 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.137 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.136 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.135 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.134 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.133 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.132 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.131 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.130 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.129 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.128 db/migrate/20170831084331_create_hd_diary_slots.rb