From 9795934bf9e5d42198278168d03d69fb26eebe73 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Mon, 20 Mar 2017 17:08:44 -0400 Subject: [PATCH] Remove MiqQueue rows containing a class removed in Rails 5. https://bugzilla.redhat.com/show_bug.cgi?id=1434454 The PostgreSQL::OID::Integer class was removed in: https://github.com/rails/rails/commit/aafee233fb3b4211ee0bfb1fca776c159bd1067e It's possible that old Rails 4.2 versions of objects could have been serialized in the MiqQueue in the args column and we won't be able to deserialize them with Rails 5+, so we need to remove these rows. Related to https://github.com/ManageIQ/manageiq/pull/14365 Related to https://bugzilla.redhat.com/show_bug.cgi?id=1429747 --- ..._remove_oid_integer_args_from_miq_queue.rb | 8 ++++++ ...ve_oid_integer_args_from_miq_queue_spec.rb | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 db/migrate/20170320195659_remove_oid_integer_args_from_miq_queue.rb create mode 100644 spec/migrations/20170320195659_remove_oid_integer_args_from_miq_queue_spec.rb diff --git a/db/migrate/20170320195659_remove_oid_integer_args_from_miq_queue.rb b/db/migrate/20170320195659_remove_oid_integer_args_from_miq_queue.rb new file mode 100644 index 00000000000..6afa5823889 --- /dev/null +++ b/db/migrate/20170320195659_remove_oid_integer_args_from_miq_queue.rb @@ -0,0 +1,8 @@ +class RemoveOidIntegerArgsFromMiqQueue < ActiveRecord::Migration[5.0] + class MiqQueue < ActiveRecord::Base; end + def up + say_with_time("Removing MiqQueue rows with args column values containing a class removed from Rails 5: PostgreSQL::OID::Integer.") do + MiqQueue.where("args LIKE '%PostgreSQL::OID::Integer%'").delete_all + end + end +end diff --git a/spec/migrations/20170320195659_remove_oid_integer_args_from_miq_queue_spec.rb b/spec/migrations/20170320195659_remove_oid_integer_args_from_miq_queue_spec.rb new file mode 100644 index 00000000000..825d22f343c --- /dev/null +++ b/spec/migrations/20170320195659_remove_oid_integer_args_from_miq_queue_spec.rb @@ -0,0 +1,27 @@ +require_migration + +describe RemoveOidIntegerArgsFromMiqQueue do + let(:queue_stub) { migration_stub(:MiqQueue) } + + migration_context :up do + it 'deletes rows with PostgreSQL::OID:Integer class serialized in args' do + args = <<-EOS +--- +- !ruby/object:ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer + precision: + scale: + limit: 8 + range: !ruby/range + begin: -9223372036854775808 + end: 9223372036854775808 + excl: true +EOS + queue_stub.create(:state => "ready", :args => args) + queue_stub.create(:state => "ready", :method_name => "stuff") + migrate + + expect(queue_stub.count).to eq(1) + expect(queue_stub.where(:method_name => "stuff").count).to eq(1) + end + end +end