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.1.1 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.1.0 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.167 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.166 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.165 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.164 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.163 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.162 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.161 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.160 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.159 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.158 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.157 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.156 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.155 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.153 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.152 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.151 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.149 db/migrate/20170831084331_create_hd_diary_slots.rb
renalware-core-2.0.148 db/migrate/20170831084331_create_hd_diary_slots.rb