You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20180923082945_change_sqlite_booleans_to_0_and_1.rb 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. class ChangeSqliteBooleansTo0And1 < ActiveRecord::Migration[5.2]
  2. COLUMNS = {
  3. AuthSource => ['onthefly_register', 'tls'],
  4. CustomFieldEnumeration => ['active'],
  5. CustomField => ['is_required', 'is_for_all', 'is_filter', 'searchable', 'editable', 'visible', 'multiple'],
  6. EmailAddress => ['is_default', 'notify'],
  7. Enumeration => ['is_default', 'active'],
  8. Import => ['finished'],
  9. IssueStatus => ['is_closed'],
  10. Issue => ['is_private'],
  11. Journal => ['private_notes'],
  12. Member => ['mail_notification'],
  13. Message => ['locked'],
  14. Project => ['is_public', 'inherit_members'],
  15. Repository => ['is_default'],
  16. Role => ['assignable', 'all_roles_managed'],
  17. Tracker => ['is_in_chlog', 'is_in_roadmap'],
  18. UserPreference => ['hide_mail'],
  19. User => ['admin', 'must_change_passwd'],
  20. WikiPage => ['protected'],
  21. WorkflowRule => ['assignee', 'author'],
  22. }
  23. def up
  24. if /sqlite/i.match?(ActiveRecord::Base.connection.adapter_name)
  25. COLUMNS.each do |klass, columns|
  26. columns.each do |column|
  27. klass.where("#{column} = 't'").update_all(column => 1)
  28. klass.where("#{column} = 'f'").update_all(column => 0)
  29. end
  30. end
  31. end
  32. end
  33. def down
  34. if /sqlite/i.match?(ActiveRecord::Base.connection.adapter_name)
  35. COLUMNS.each do |klass, columns|
  36. columns.each do |column|
  37. klass.where("#{column} = 1").update_all(column => 't')
  38. klass.where("#{column} = 0").update_all(column => 'f')
  39. end
  40. end
  41. end
  42. end
  43. end