Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate MiddlewareServer to MiddlewareServerWildfly and MiddlewareServerEap #81

Merged
merged 5 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class MigrateMiddlewareServerToWildflyAndEap < ActiveRecord::Migration[5.0]
class MiddlewareServer < ActiveRecord::Base
self.inheritance_column = :_type_disabled
end

def up
say_with_time('Migrating middleware_server to middleware_server_wildfly') do
MiddlewareServer
.where("type = ? AND product ~* ?", 'ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer', 'wildfly')
.update_all(:type => 'ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServerWildfly')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the new wildfly/eap class be a subclass/subtype of middleware server class? here it seems it's in hierarchy of middleware_manager, or I am probably missing something

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they are better included in middleware_manager as well, so that we have proper namespacing for the resources, what do you think?

Another option would be ManageIQ::Providers::Hawkular::WildFlyServer. Any of the two are fine by me.

end

say_with_time('Migrating middleware_server to middleware_server_eap') do
MiddlewareServer
.where("type = ? AND product ~* ?", 'ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer', 'eap')
.update_all(:type => 'ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServerEap')
end
end

def down
say_with_time('Migrating middleware_server_wildfly to middleware_server') do
MiddlewareServer
.where(:type => 'ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServerWildfly')
.update_all(:type => 'ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer')
end

say_with_time('Migrating middleware_server_eap to middleware_server') do
MiddlewareServer
.where(:type => 'ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServerEap')
.update_all(:type => 'ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer')
end
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require_migration

describe MigrateMiddlewareServerToWildflyAndEap do
let(:mw_server_stub) { migration_stub(:MiddlewareServer) }

migration_context :up do
it "sets new type for WildFly server" do
mw_server = mw_server_stub.create!(
:type => "ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer",
:product => "WildFly Full"
)
migrate
expect(mw_server.reload).to have_attributes(
:type => "ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServerWildfly"
)
end

it "sets new type for EAP server" do
mw_server = mw_server_stub.create!(
:type => "ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer",
:product => "JBoss EAP"
)
migrate
expect(mw_server.reload).to have_attributes(
:type => "ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServerEap"
)
end

it "leave type unchanged for other mw servers" do
mw_server = mw_server_stub.create!(
:type => "ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer",
:product => "Hawkular"
)
migrate
expect(mw_server.reload).to have_attributes(
:type => "ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer"
)
end
end

migration_context :down do
it "reverts type for WildFly" do
mw_server = mw_server_stub.create!(:type => "ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServerWildfly")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both local assignments should be extracted to let, and the migration to be run in a before filter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please point me to an example? I can't find any other migration which would be using it... Or maybe I just don't understand the suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cfcosta, does it make any difference here to move two assignments from test cases into two lets?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked on other migration tests, it seems like all of them are done the way you did them, so 🚢 it.

migrate
expect(mw_server.reload).to have_attributes(:type => "ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer")
end

it "reverts type for EAP server" do
mw_server = mw_server_stub.create!(:type => "ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServerEap")
migrate
expect(mw_server.reload).to have_attributes(:type => "ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer")
end
end
end