From 24e595fe9191b73effb5acffc35dbf1b50a69499 Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Fri, 21 Apr 2017 16:21:40 -0400 Subject: [PATCH 1/5] Added a new column to store embedded method names --- app/models/miq_ae_method.rb | 1 + .../20170421193150_add_embedded_methods_to_miq_ae_method.rb | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb diff --git a/app/models/miq_ae_method.rb b/app/models/miq_ae_method.rb index e74d7f26204..b6901eb8ac8 100644 --- a/app/models/miq_ae_method.rb +++ b/app/models/miq_ae_method.rb @@ -3,6 +3,7 @@ class MiqAeMethod < ApplicationRecord include MiqAeSetUserInfoMixin include MiqAeYamlImportExportMixin + serialize :embedded_methods, Array belongs_to :ae_class, :class_name => "MiqAeClass", :foreign_key => :class_id has_many :inputs, -> { order :priority }, :class_name => "MiqAeField", :foreign_key => :method_id, diff --git a/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb b/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb new file mode 100644 index 00000000000..add02ad5ba9 --- /dev/null +++ b/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb @@ -0,0 +1,5 @@ +class AddEmbeddedMethodsToMiqAeMethod < ActiveRecord::Migration[5.0] + def change + add_column :miq_ae_methods, :embedded_methods, :string, array: true, default: [] + end +end From 16db25ced04d9a2770948ba0ae6e59323c9fc63c Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Fri, 21 Apr 2017 17:56:59 -0400 Subject: [PATCH 2/5] Fixed rubocop warnings, added default_value_for --- app/models/miq_ae_method.rb | 1 + .../20170421193150_add_embedded_methods_to_miq_ae_method.rb | 2 +- db/schema.yml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/miq_ae_method.rb b/app/models/miq_ae_method.rb index b6901eb8ac8..ff7988ab895 100644 --- a/app/models/miq_ae_method.rb +++ b/app/models/miq_ae_method.rb @@ -4,6 +4,7 @@ class MiqAeMethod < ApplicationRecord include MiqAeSetUserInfoMixin include MiqAeYamlImportExportMixin serialize :embedded_methods, Array + default_value_for :embedded_methods, [] belongs_to :ae_class, :class_name => "MiqAeClass", :foreign_key => :class_id has_many :inputs, -> { order :priority }, :class_name => "MiqAeField", :foreign_key => :method_id, diff --git a/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb b/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb index add02ad5ba9..0f95c2297be 100644 --- a/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb +++ b/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb @@ -1,5 +1,5 @@ class AddEmbeddedMethodsToMiqAeMethod < ActiveRecord::Migration[5.0] def change - add_column :miq_ae_methods, :embedded_methods, :string, array: true, default: [] + add_column :miq_ae_methods, :embedded_methods, :string, :array => true end end diff --git a/db/schema.yml b/db/schema.yml index becc8b75e7d..4616fd7dc02 100644 --- a/db/schema.yml +++ b/db/schema.yml @@ -4803,6 +4803,7 @@ miq_ae_methods: - updated_on - updated_by - updated_by_user_id +- embedded_methods miq_ae_namespaces: - id - parent_id From 62ecc08a145daf66b14e4ab8489290f4310e3340 Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Tue, 25 Apr 2017 16:02:08 -0400 Subject: [PATCH 3/5] PR feedback Changed to use text instead of string Removed the serialize --- app/models/miq_ae_method.rb | 1 - .../20170421193150_add_embedded_methods_to_miq_ae_method.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/miq_ae_method.rb b/app/models/miq_ae_method.rb index ff7988ab895..a219f598465 100644 --- a/app/models/miq_ae_method.rb +++ b/app/models/miq_ae_method.rb @@ -3,7 +3,6 @@ class MiqAeMethod < ApplicationRecord include MiqAeSetUserInfoMixin include MiqAeYamlImportExportMixin - serialize :embedded_methods, Array default_value_for :embedded_methods, [] belongs_to :ae_class, :class_name => "MiqAeClass", :foreign_key => :class_id diff --git a/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb b/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb index 0f95c2297be..eec4d63caef 100644 --- a/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb +++ b/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb @@ -1,5 +1,5 @@ class AddEmbeddedMethodsToMiqAeMethod < ActiveRecord::Migration[5.0] def change - add_column :miq_ae_methods, :embedded_methods, :string, :array => true + add_column :miq_ae_methods, :embedded_methods, :text, :array => true end end From 024f463d09f8ea84a4190c73b71309e36a3859d5 Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Fri, 28 Apr 2017 16:46:20 -0400 Subject: [PATCH 4/5] Added migration to update existing methods --- ...21193150_add_embedded_methods_to_miq_ae_method.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb b/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb index eec4d63caef..65429148431 100644 --- a/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb +++ b/db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb @@ -1,5 +1,13 @@ class AddEmbeddedMethodsToMiqAeMethod < ActiveRecord::Migration[5.0] - def change - add_column :miq_ae_methods, :embedded_methods, :text, :array => true + class MiqAeMethod < ActiveRecord::Base; end + def up + add_column :miq_ae_methods, :embedded_methods, :text, :array => true, :comment => "Ordered list of embedded method names" + say_with_time("Updating existing miq_ae_methods embedded methods") do + MiqAeMethod.update_all(:embedded_methods => []) + end + end + + def down + remove_column :miq_ae_methods, :embedded_methods end end From 3da21cb287399b355c20bbf8a34e7a9149e6e2e0 Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Mon, 1 May 2017 10:46:44 -0400 Subject: [PATCH 5/5] Added migration spec --- ...dd_embedded_methods_to_miq_ae_method_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 spec/migrations/20170421193150_add_embedded_methods_to_miq_ae_method_spec.rb diff --git a/spec/migrations/20170421193150_add_embedded_methods_to_miq_ae_method_spec.rb b/spec/migrations/20170421193150_add_embedded_methods_to_miq_ae_method_spec.rb new file mode 100644 index 00000000000..ae2eea78cb3 --- /dev/null +++ b/spec/migrations/20170421193150_add_embedded_methods_to_miq_ae_method_spec.rb @@ -0,0 +1,17 @@ +require_migration + +describe AddEmbeddedMethodsToMiqAeMethod do + let(:miq_ae_method_stub) { migration_stub(:MiqAeMethod) } + + migration_context :up do + it "adds embedded_methods and sets it to []" do + miq_ae_method_stub.create!(:name => 'method1', :class_id => 10) + miq_ae_method_stub.create!(:name => 'method2', :class_id => 10) + + migrate + + expect(miq_ae_method_stub.count).to eq(2) + expect(miq_ae_method_stub.first.embedded_methods).to eq([]) + end + end +end