20240930184012_checklist_improve_reference_tracking.rb 940 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class ChecklistImproveReferenceTracking < ActiveRecord::Migration[7.1]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. add_default_empty_strings
  7. add_indexes
  8. change_column_null :checklists, :ticket_id, false
  9. end
  10. private
  11. def add_default_empty_strings
  12. change_column_default :checklists, :name, ''
  13. change_column_default :checklist_templates, :name, ''
  14. # MySQL does not support default text on non-null text items
  15. return if ActiveRecord::Base.connection_db_config.configuration_hash[:adapter] == 'mysql2'
  16. change_column_default :checklist_items, :text, ''
  17. change_column_default :checklist_template_items, :text, ''
  18. end
  19. def add_indexes
  20. add_index :checklist_items, :checked
  21. add_index :checklist_templates, :active
  22. end
  23. end