-
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.
Merge pull request #718 from Guddetisandeep/update_resource_pool_iden…
…tifiers Update resource pool feature identifiers to infrastructure-specific
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
db/migrate/20240516101409_updateresourcepoolidentifierstomiqproductfeatures.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,35 @@ | ||
class Updateresourcepoolidentifierstomiqproductfeatures < ActiveRecord::Migration[6.1] | ||
class MiqProductFeature < ActiveRecord::Base; end | ||
|
||
FEATURE_MAPPING_UPDATE = { | ||
'resource_pool' => 'resource_pool_infra', | ||
'resource_pool_view' => 'resource_pool_infra_view', | ||
'resource_pool_show_list' => 'resource_pool_infra_show_list', | ||
'resource_pool_show' => 'resource_pool_infra_show', | ||
'resource_pool_control' => 'resource_pool_infra_control', | ||
'resource_pool_tag' => 'resource_pool_infra_tag', | ||
'resource_pool_protect' => 'resource_pool_infra_protect', | ||
'resource_pool_admin' => 'resource_pool_infra_admin', | ||
'resource_pool_delete' => 'resource_pool_infra_delete' | ||
}.freeze | ||
|
||
def up | ||
return if MiqProductFeature.none? | ||
|
||
say_with_time('Updating resource_pool features to resource_pool_infra') do | ||
FEATURE_MAPPING_UPDATE.each do |from, to| | ||
MiqProductFeature.find_by(:identifier => from)&.update!(:identifier => to) | ||
end | ||
end | ||
end | ||
|
||
def down | ||
return if MiqProductFeature.none? | ||
|
||
say_with_time('Reverting resource_pool_infra features back to resource_pool') do | ||
FEATURE_MAPPING_UPDATE.each do |to, from| | ||
MiqProductFeature.find_by(:identifier => from)&.update!(:identifier => to) | ||
end | ||
end | ||
end | ||
end |
39 changes: 39 additions & 0 deletions
39
spec/migrations/20240516101409_updateresourcepoolidentifierstomiqproductfeatures_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,39 @@ | ||
require_migration | ||
|
||
describe Updateresourcepoolidentifierstomiqproductfeatures do | ||
let(:miq_product_feature) { migration_stub(:MiqProductFeature) } | ||
|
||
before do | ||
%w[resource_pool resource_pool_view resource_pool_show_list resource_pool_show resource_pool_control resource_pool_tag resource_pool_protect resource_pool_admin resource_pool_delete].each do |identifier| | ||
miq_product_feature.create!(:identifier => identifier) | ||
end | ||
end | ||
|
||
migration_context :up do | ||
it "updates existing resource_pool features to resource_pool_infra" do | ||
migrate | ||
|
||
described_class::FEATURE_MAPPING_UPDATE.each do |old_identifier, new_identifier| | ||
expect(miq_product_feature.exists?(:identifier => old_identifier)).to be_falsy | ||
expect(miq_product_feature.exists?(:identifier => new_identifier)).to be_truthy | ||
end | ||
end | ||
end | ||
|
||
migration_context :down do | ||
before do | ||
described_class::FEATURE_MAPPING_UPDATE.each do |_old_identifier, new_identifier| | ||
miq_product_feature.create!(:identifier => new_identifier) | ||
end | ||
end | ||
|
||
it "reverts resource_pool_infra features back to resource_pool" do | ||
migrate | ||
|
||
described_class::FEATURE_MAPPING_UPDATE.each do |old_identifier, new_identifier| | ||
expect(miq_product_feature.exists?(:identifier => new_identifier)).to be_falsy | ||
expect(miq_product_feature.exists?(:identifier => old_identifier)).to be_truthy | ||
end | ||
end | ||
end | ||
end |