Skip to content

Commit

Permalink
Add Comp.System, Hardware and Op. System indexes
Browse files Browse the repository at this point in the history
Add Comp.System, Hardware and Op. System indexes
  • Loading branch information
Ladas committed Nov 1, 2017
1 parent 37e58c0 commit eac24ca
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ContainerImageRegistry < ActiveRecord::Base; end

class ContainerCondition < ActiveRecord::Base; end
class SecurityContext < ActiveRecord::Base; end
class ComputerSystem < ActiveRecord::Base; end
class ContainerEnvVar < ActiveRecord::Base; end
class ContainerLimitItem < ActiveRecord::Base; end
class ContainerPortConfig < ActiveRecord::Base; end
Expand All @@ -30,6 +31,8 @@ class ContainerServicePortConfig < ActiveRecord::Base; end
class ContainerTemplateParameter < ActiveRecord::Base; end
class ContainerVolume < ActiveRecord::Base; end
class CustomAttribute < ActiveRecord::Base; end
class Hardware < ActiveRecord::Base; end
class OperatingSystem < ActiveRecord::Base; end

class ContainerDefinition < ActiveRecord::Base; end
class Container < ActiveRecord::Base
Expand Down Expand Up @@ -65,6 +68,7 @@ def cleanup_duplicate_data_delete_all(model, unique_index_columns)
# Nested tables, not having :ems_id and the foreign_key is a part of the unique index
ContainerCondition => [:container_entity_id, :container_entity_type, :name],
SecurityContext => [:resource_id, :resource_type],
ComputerSystem => [:managed_entity_id, :managed_entity_type],
ContainerEnvVar => [:container_definition_id, :name, :value, :field_path],
ContainerLimitItem => [:container_limit_id, :resource, :item_type],
ContainerPortConfig => [:container_definition_id, :ems_ref],
Expand All @@ -73,6 +77,8 @@ def cleanup_duplicate_data_delete_all(model, unique_index_columns)
ContainerTemplateParameter => [:container_template_id, :name],
ContainerVolume => [:parent_id, :parent_type, :name],
CustomAttribute => [:resource_id, :resource_type, :name, :unique_name, :section, :source],
Hardware => [:vm_or_template_id, :host_id, :computer_system_id],
OperatingSystem => [:vm_or_template_id, :host_id, :computer_system_id],
# Questionable
ContainerDefinition => [:ems_id, :ems_ref],
Container => [:ems_id, :ems_ref]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def change
[:resource_id, :resource_type],
:unique => true,
:name => "index_security_contexts_unique_multi_column"
add_index :computer_systems,
[:managed_entity_id, :managed_entity_type],
:unique => true,
:name => "index_computer_systems_unique_multi_column"
add_index :container_env_vars,
[:container_definition_id, :name, :value, :field_path],
:unique => true,
Expand Down Expand Up @@ -65,6 +69,14 @@ def change
[:resource_id, :resource_type, :name, :unique_name, :section, :source],
:unique => true,
:name => "index_custom_attributes_parameters_unique_multi_column"
add_index :hardwares,
[:vm_or_template_id, :host_id, :computer_system_id],
:unique => true,
:name => "index_hardwares_on_unique_multi_column"
add_index :operating_systems,
[:vm_or_template_id, :host_id, :computer_system_id],
:unique => true,
:name => "index_operating_systems_unique_multi_column"

# FIXME(lsmola) questionable, these were modeled as nested, but they have :ems_id & :ems_ref
# Is ems_ref unique? we were saving these under container_group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,43 @@ def assert_before_migration_test_data(model, original_values, duplicate_values)
expect(model.count).to eq(10)

# Check there are 5 duplicates in the data
expect(original_values.count).to eq(5)
expect(duplicate_values.count).to eq(5)
expect(original_values.count).to eq(original_values_count(model))
expect(duplicate_values.values.flatten.count).to eq(duplicate_values_count(model))

# Check that original values ids are the min or all duplicated ids
original_values.each do |key, value|
expect((duplicate_values[key] << value).min).to eq value
end
end

def assert_after_migration_test_data(model, original_values, duplicate_values)
expect(model.count).to eq(5)
def assert_after_migration_test_data(model, original_values, _duplicate_values)
expect(model.count).to eq(original_values_count(model))

model.all.each do |record|
expect(original_values[record.attributes.symbolize_keys.slice(*model_unique_keys(model))]).to eq record.id
end
end

def original_values_count(model)
if [CleanUpDuplicatesInContainersTables::Hardware,
CleanUpDuplicatesInContainersTables::OperatingSystem].include? model
# These models do not have any ems_ref like field
4
else
5
end
end

def duplicate_values_count(model)
if [CleanUpDuplicatesInContainersTables::Hardware,
CleanUpDuplicatesInContainersTables::OperatingSystem].include? model
# These models do not have any ems_ref like field
6
else
5
end
end

migration_context :up do
it "manually checks we clean up duplicates in ContainerBuild build model" do
model = CleanUpDuplicatesInContainersTables::ContainerBuild
Expand Down

0 comments on commit eac24ca

Please sign in to comment.