20230508101744_tech_debt_297_three_state_boolean.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class TechDebt297ThreeStateBoolean < ActiveRecord::Migration[6.1]
  3. def up
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. users_vip
  7. roles_default_at_signup
  8. import_jobs_dry_run
  9. tokens_persistent
  10. change_column_default :ticket_article_types, :communication, false
  11. change_column_default :settings, :frontend, false
  12. Rails.cache.clear
  13. end
  14. private
  15. def users_vip
  16. User.where(vip: nil).in_batches.each_record do |user|
  17. user.update_columns(vip: false) # rubocop:disable Rails/SkipsModelValidations
  18. end
  19. change_column_null :users, :vip, false, false
  20. end
  21. def roles_default_at_signup
  22. Role.where(default_at_signup: nil).each do |role|
  23. role.update_columns(default_at_signup: false) # rubocop:disable Rails/SkipsModelValidations
  24. end
  25. change_column_null :roles, :default_at_signup, false, false
  26. end
  27. def import_jobs_dry_run
  28. ImportJob.where(dry_run: nil).each do |import_job|
  29. import_job.update_columns(dry_run: false) # rubocop:disable Rails/SkipsModelValidations
  30. end
  31. change_column_null :import_jobs, :dry_run, false, false
  32. end
  33. def tokens_persistent
  34. Token.where(persistent: nil).each do |token|
  35. token.update_columns(persistent: false) # rubocop:disable Rails/SkipsModelValidations
  36. end
  37. change_column_default :tokens, :persistent, false
  38. change_column_null :tokens, :persistent, false, false
  39. end
  40. end