Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
yrudman committed Nov 13, 2019
1 parent e5455fd commit 546c151
Showing 2 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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,48 @@
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

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 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 546c151

Please sign in to comment.