20250124112935_reserved_words_per_model.rb 813 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. class ReservedWordsPerModel < ActiveRecord::Migration[7.2]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. reserved_name = 'article'
  7. sanitized_name = '_article'
  8. # Rename column in database.
  9. if ActiveRecord::Base.connection.columns(Ticket.table_name).map(&:name).include?(reserved_name)
  10. ActiveRecord::Migration.rename_column(:tickets, reserved_name.to_sym, sanitized_name.to_sym)
  11. Ticket.reset_column_information
  12. end
  13. # Rename the attribute itself.
  14. attribute = ObjectManager::Attribute.get(
  15. object: Ticket.to_app_model,
  16. name: reserved_name,
  17. )
  18. return if !attribute
  19. attribute.update!(name: sanitized_name)
  20. end
  21. end