trabajo-afectivo/db/migrate/20170419000002_overview_role_ids.rb

29 lines
732 B
Ruby
Raw Permalink Normal View History

# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
2017-09-08 08:28:34 +00:00
class OverviewRoleIds < ActiveRecord::Migration[4.2]
2017-04-19 19:54:04 +00:00
def up
# return if it's a new setup
return if !Setting.exists?(name: 'system_init_done')
2017-04-19 19:54:04 +00:00
create_table :overviews_roles, id: false do |t|
t.integer :overview_id
t.integer :role_id
end
add_index :overviews_roles, [:overview_id]
add_index :overviews_roles, [:role_id]
Overview.connection.schema_cache.clear!
Overview.reset_column_information
Overview.all.each do |overview|
2017-04-19 19:54:04 +00:00
next if overview.role_id.blank?
2017-04-19 19:54:04 +00:00
overview.role_ids = [overview.role_id]
overview.save!
end
2017-04-19 19:54:04 +00:00
remove_column :overviews, :role_id
Cache.clear
2017-04-19 19:54:04 +00:00
end
end