forked from ManageIQ/manageiq-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate existing product features to handle renames from core 22971
Related to: ManageIQ/manageiq#22971
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
db/migrate/20240401185807_rename_ansible_specific_tag_features_to_be_generic.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,30 @@ | ||
class RenameAnsibleSpecificTagFeaturesToBeGeneric < ActiveRecord::Migration[6.1] | ||
class MiqProductFeature < ActiveRecord::Base; end | ||
class MiqRolesFeature < ActiveRecord::Base; end | ||
|
||
FEATURE_MAPPING = { | ||
'ansible_repository_tag' => 'embedded_configuration_script_source_tag', | ||
'ansible_credential_tag' => 'embedded_automation_manager_credential_tag', | ||
}.freeze | ||
|
||
def up | ||
return if MiqProductFeature.none? | ||
|
||
say_with_time 'Renaming ansible specific product features to be generic embedded' do | ||
# Direct renaming of features | ||
FEATURE_MAPPING.each do |from, to| | ||
MiqProductFeature.find_by(:identifier => from)&.update!(:identifier => to) | ||
end | ||
end | ||
end | ||
|
||
def down | ||
return if MiqProductFeature.none? | ||
|
||
say_with_time 'Renaming generic embedded product features back to specific ansible ones' do | ||
FEATURE_MAPPING.each do |to, from| | ||
MiqProductFeature.find_by(:identifier => from)&.update!(:identifier => to) | ||
end | ||
end | ||
end | ||
end |
41 changes: 41 additions & 0 deletions
41
spec/migrations/20240401185807_rename_ansible_specific_tag_features_to_be_generic_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,41 @@ | ||
require_migration | ||
|
||
describe RenameAnsibleSpecificTagFeaturesToBeGeneric do | ||
let(:user_role_id) { id_in_current_region(1) } | ||
let(:feature_stub) { migration_stub :MiqProductFeature } | ||
let(:roles_feature_stub) { migration_stub :MiqRolesFeature } | ||
|
||
migration_context :up do | ||
describe 'product features renaming' do | ||
it 'renames the features' do | ||
RenameAnsibleSpecificTagFeaturesToBeGeneric::FEATURE_MAPPING.keys.each do |identifier| | ||
feature = feature_stub.create!(:identifier => identifier) | ||
roles_feature_stub.create!(:miq_product_feature_id => feature.id, :miq_user_role_id => user_role_id) | ||
end | ||
|
||
migrate | ||
|
||
RenameAnsibleSpecificTagFeaturesToBeGeneric::FEATURE_MAPPING.values.each do |identifier| | ||
expect(feature_stub.find_by_identifier(identifier)).to be_truthy | ||
end | ||
end | ||
end | ||
end | ||
|
||
migration_context :down do | ||
describe 'product features revert' do | ||
it 'reverts the Ansible Tower Provider explorer features' do | ||
RenameAnsibleSpecificTagFeaturesToBeGeneric::FEATURE_MAPPING.values.each do |identifier| | ||
feature = feature_stub.create!(:identifier => identifier) | ||
roles_feature_stub.create!(:miq_product_feature_id => feature.id, :miq_user_role_id => user_role_id) | ||
end | ||
|
||
migrate | ||
|
||
RenameAnsibleSpecificTagFeaturesToBeGeneric::FEATURE_MAPPING.keys.each do |identifier| | ||
expect(feature_stub.find_by_identifier(identifier)).to be_truthy | ||
end | ||
end | ||
end | ||
end | ||
end |