20180812123222_change_relays_enabled.rb 696 B

1234567891011121314151617181920212223
  1. # frozen_string_literal: true
  2. class ChangeRelaysEnabled < ActiveRecord::Migration[5.2]
  3. def up
  4. # The relays table is supposed to be very small,
  5. # single-digit number of rows, so this should be fine
  6. safety_assured do
  7. add_column :relays, :state, :integer, default: 0, null: false
  8. # At the time of this migration, no relays reject anyone, so if
  9. # there are enabled ones, they are accepted
  10. execute 'UPDATE relays SET state = 2 WHERE enabled = true'
  11. remove_column :relays, :enabled
  12. end
  13. end
  14. def down
  15. change_table(:relays, bulk: true) do |t|
  16. t.remove :state
  17. t.column :enabled, :boolean, default: false, null: false
  18. end
  19. end
  20. end