20230726082734_smime_meta_information_table.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class SMIMEMetaInformationTable < ActiveRecord::Migration[6.1]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. migrate_table
  7. end
  8. private
  9. def migrate_table
  10. change_table :smime_certificates do |t|
  11. remove_columns(t)
  12. rename_columns(t)
  13. add_columns(t)
  14. end
  15. SMIMECertificate.reset_column_information
  16. end
  17. def remove_columns(t)
  18. t.remove_index :modulus if t.index_exists?(:modulus)
  19. t.remove_index :subject if t.index_exists?(:subject)
  20. t.remove :subject, :doc_hash, :not_before_at, :not_after_at
  21. end
  22. def rename_columns(t)
  23. t.rename :modulus, :uid
  24. t.rename :raw, :pem
  25. end
  26. def add_columns(t)
  27. if Rails.application.config.db_column_array
  28. t.column :email_addresses, :string, null: true, array: true
  29. else
  30. t.column :email_addresses, :json, null: true
  31. end
  32. t.string :issuer_hash, limit: 128, null: true
  33. t.string :subject_hash, limit: 128, null: true
  34. t.index [:uid]
  35. end
  36. end