Skip to content

Commit

Permalink
Subclass Storages by provider
Browse files Browse the repository at this point in the history
Now that a Storage record belongs_to an EMS we can subclass the storages
by provider.
  • Loading branch information
agrare committed Dec 10, 2019
1 parent de7d691 commit 0c01474
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions db/migrate/20191210162908_add_type_to_storages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTypeToStorages < ActiveRecord::Migration[5.1]
def change
add_column :storages, :type, :string
end
end
32 changes: 32 additions & 0 deletions db/migrate/20191210163518_subclass_storages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class SubclassStorages < ActiveRecord::Migration[5.1]
class ExtManagementSystem < ActiveRecord::Base
self.inheritance_column = :_type_disabled
end

class Storage < ActiveRecord::Base
include ActiveRecord::IdRegions

self.inheritance_column = :_type_disabled

belongs_to :ext_management_system, :foreign_key => :ems_id, :class_name => "SubclassStorages::ExtManagementSystem"
end

def up
[
'Microsoft',
'Redhat',
'Vmware',
].each do |provider|
ems_class_name = "ManageIQ::Providers::#{provider}::InfraManager"
storage_class_name = "#{ems_class_name}::Storage"
Storage.in_my_region
.joins(:ext_management_system)
.where(:ext_management_systems => {:type => ems_class_name})
.update_all(:type => storage_class_name)
end
end

def down
Storage.in_my_region.update_all(:type => nil)
end
end

0 comments on commit 0c01474

Please sign in to comment.