Skip to content

Commit

Permalink
clone miq_tasks#owner_id to miq_tasks#group_id for dashboards assigne…
Browse files Browse the repository at this point in the history
…d to group

This PR should go together with ManageIQ/manageiq#19491
Fixes issue ManageIQ/manageiq#18924
  • Loading branch information
yrudman committed Nov 13, 2019
1 parent e5455fd commit d356240
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CopyOwnerIdToGroupIdForDashboards < ActiveRecord::Migration[5.1]
class MiqSet < ActiveRecord::Base; end

def up
say_with_time("Copying owner_id to group_id in miq_sets table for each dashboard assigned to group") do
MiqSet.where(:set_type => "MiqWidgetSet", :owner_type => "MiqGroup").find_each do |dashboard|
dashboard.update(:group_id => dashboard.owner_id)
end
end
end

def down
say_with_time("Nullifying group_id column in miw_sets table for each dashboard assigned to group") do
MiqSet.where(:set_type => "MiqWidgetSet", :owner_type => "MiqGroup").find_each do |dashboard|
dashboard.update(:group_id => nil)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require_migration

describe CopyOwnerIdToGroupIdForDashboards do
let(:miq_set) { migration_stub(:MiqSet) }
let(:name) { "Hello Dashboard" }
let(:group_id) { 1 }

migration_context :up do
it "Copying owner_id to group_id in miq_sets table for each dashboard assigned to group only" do
dashboard = miq_set.create!(:name => name, :set_type => "MiqWidgetSet", :owner_type => "MiqGroup", :owner_id => group_id)

migrate

expect(dashboard.reload.group_id).to eq(group_id)
end
end

migration_context :down do
it "Nullifying group_id column in miw_sets table for each dashboard assigned to group" do
dashboard = miq_set.create!(:name => name, :set_type => "MiqWidgetSet", :owner_type => "MiqGroup", :owner_id => group_id, :group_id => group_id)

migrate

expect(dashboard.reload.group_id).to be nil
end
end
end

0 comments on commit d356240

Please sign in to comment.