Skip to content

Commit

Permalink
Migrate existing product features to handle renames from core 22971
Browse files Browse the repository at this point in the history
  • Loading branch information
jrafanie committed Apr 1, 2024
1 parent bf4e4b5 commit fff551e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
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
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

0 comments on commit fff551e

Please sign in to comment.