20170419000002_overview_role_ids.rb 656 B

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