-
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 #706 from kbrock/vim_string_migrations
Remove VimStrings from MiqQueue
- Loading branch information
Showing
7 changed files
with
98 additions
and
88 deletions.
There are no files selected for viewing
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
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
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
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
16 changes: 16 additions & 0 deletions
16
db/migrate/20230919143746_remove_vim_strings_from_miq_queue.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,16 @@ | ||
class RemoveVimStringsFromMiqQueue < ActiveRecord::Migration[6.1] | ||
disable_ddl_transaction! | ||
include MigrationHelper | ||
|
||
class MiqQueue < ActiveRecord::Base | ||
end | ||
|
||
def up | ||
regex_replace_column_value(MiqQueue, 'args', '!ruby/string:VimString', '!ruby/string:String') | ||
regex_replace_column_value(MiqQueue, 'args', '!ruby/hash-with-ivars:VimHash', '!ruby/hash-with-ivars:Hash') | ||
end | ||
|
||
# this is very old, not rolling back | ||
def down | ||
end | ||
end |
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
54 changes: 54 additions & 0 deletions
54
spec/migrations/20230919143746_remove_vim_strings_from_miq_queue_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,54 @@ | ||
require_migration | ||
|
||
# This is mostly necessary for data migrations, so feel free to delete this | ||
# file if you do no need it. | ||
describe RemoveVimStringsFromMiqQueue do | ||
let(:miq_queue_stub) { migration_stub(:MiqQueue) } | ||
|
||
migration_context :up do | ||
it "converts VimStrings to Strings" do | ||
queue_args = <<~CONTEXT | ||
--- | ||
- :event_type: DrsMigrateVM_Task | ||
:chain_id: &1 !ruby/string:VimString | ||
str: '12345678' | ||
xsiType: :SOAP::SOAPInt | ||
vimType: | ||
:is_task: true | ||
:source: VC | ||
:message: &3 !ruby/string:VimString | ||
str: 'Task: Migrate virtual machine' | ||
xsiType: :SOAP::SOAPString | ||
vimType: | ||
:timestamp: &2 !ruby/string:VimString | ||
str: '2022-10-06T06:40:59.901255Z' | ||
xsiType: :SOAP::SOAPDateTime | ||
vimType: | ||
:full_data: !ruby/hash-with-ivars:VimHash | ||
elements: | ||
key: !ruby/string:VimString | ||
str: '12345678' | ||
xsiType: :SOAP::SOAPInt | ||
vimType: | ||
chainId: *1 | ||
createdTime: *2 | ||
userName: !ruby/string:VimString | ||
str: '' | ||
xsiType: :SOAP::SOAPString | ||
vimType: | ||
CONTEXT | ||
|
||
queue_item = miq_queue_stub.create!( | ||
:args => queue_args | ||
) | ||
|
||
migrate | ||
queue_item.reload | ||
|
||
args = YAML.safe_load(queue_item.args, :permitted_classes => [Symbol, Date, String, Hash], :aliases => true) | ||
arg = args.first | ||
expect(arg.class).to eq(Hash) | ||
expect(arg[:chain_id].class).to eq(String) | ||
end | ||
end | ||
end |