-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
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…
…d to group This PR should go together with ManageIQ/manageiq#19491 Fixes issue ManageIQ/manageiq#18924
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
db/migrate/20191112132759_copy_owner_id_to_group_id_for_dashboards.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
27 changes: 27 additions & 0 deletions
27
spec/migrations/20191112132759_copy_owner_id_to_group_id_for_dashboards_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |