20170419000002_overview_role_ids.rb 739 B

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class OverviewRoleIds < ActiveRecord::Migration[4.2]
  3. def up
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. create_table :overviews_roles, id: false do |t|
  7. t.integer :overview_id
  8. t.integer :role_id
  9. end
  10. add_index :overviews_roles, [:overview_id]
  11. add_index :overviews_roles, [:role_id]
  12. Overview.connection.schema_cache.clear!
  13. Overview.reset_column_information
  14. Overview.all.each do |overview|
  15. next if overview.role_id.blank?
  16. overview.role_ids = [overview.role_id]
  17. overview.save!
  18. end
  19. remove_column :overviews, :role_id
  20. Rails.cache.clear
  21. end
  22. end