Skip to content
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
36 changes: 36 additions & 0 deletions db/migrate/20251104153210_drop_log_collection_backend.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class DropLogCollectionBackend < ActiveRecord::Migration[7.2]
def up
remove_column :miq_servers, :log_file_depot_id
remove_column :zones, :log_file_depot_id

drop_table :log_files

remove_column :file_depots, :support_case
end

def down
create_table :log_files do |t|
t.string :name
t.string :description
t.string :resource_type
t.bigint :resource_id
t.bigint :miq_task_id
t.datetime :created_on, :precision => nil
t.datetime :updated_on, :precision => nil
t.datetime :logging_started_on, :precision => nil
t.datetime :logging_ended_on, :precision => nil
t.string :state
t.boolean :historical
t.string :log_uri
t.bigint :file_depot_id
t.string :local_file
t.index [:miq_task_id], :name => "index_log_files_on_miq_task_id"
t.index [:resource_id, :resource_type], :name => "index_log_files_on_resource_id_and_resource_type"
end

add_column :miq_servers, :log_file_depot_id, :bigint
add_column :zones, :log_file_depot_id, :bigint

add_column :file_depots, :support_case, :string
end
end
35 changes: 35 additions & 0 deletions db/migrate/20251104153211_drop_log_collection_configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class DropLogCollectionConfiguration < ActiveRecord::Migration[7.2]
class MiqProductFeature < ActiveRecord::Base
include ActiveRecord::IdRegions
end

class MiqRolesFeature < ActiveRecord::Base
include ActiveRecord::IdRegions
end

class SettingsChange < ActiveRecord::Base
include ActiveRecord::IdRegions
end

FEATURE_NAMES = %w[
collect_current_logs
collect_logs
log_depot_edit
zone_collect_current_logs
zone_collect_logs
zone_log_depot_edit
].freeze

def up
say_with_time("Removing log collection product features") do
MiqProductFeature.in_my_region.where(:identifier => FEATURE_NAMES).each do |feature|
MiqRolesFeature.where(:miq_product_feature_id => feature.id).delete_all
feature.delete
end
end

say_with_time("Removing log collection settings") do
SettingsChange.in_my_region.where("key LIKE ?", "/log/collection%").delete_all
Copy link
Member

Choose a reason for hiding this comment

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

wow, this is so clean... I thought it would be more to do but I think you're right, this is it. 👍

end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
iso_images.pxe_image_type_id
key_pairs_vms.authentication_id
lans.parent_id
log_files.file_depot_id
metric_rollups_01.parent_ems_cluster_id
metric_rollups_01.parent_ems_id
metric_rollups_01.parent_host_id
Expand Down Expand Up @@ -361,7 +360,6 @@
miq_roles_features.miq_product_feature_id
miq_schedules.file_depot_id
miq_schedules.resource_id
miq_servers.log_file_depot_id
miq_set_memberships.member_id
miq_widget_contents.miq_group_id
miq_widget_shortcuts.miq_shortcut_id
Expand Down Expand Up @@ -442,7 +440,6 @@
vms.storage_profile_id
windows_images.pxe_image_type_id
windows_images.pxe_server_id
zones.log_file_depot_id
])
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require_migration

class DropLogCollectionConfiguration < ActiveRecord::Migration[7.2]
class MiqUserRole < ActiveRecord::Base; end
end

describe DropLogCollectionConfiguration do
let(:miq_product_feature_stub) { migration_stub(:MiqProductFeature) }
let(:miq_roles_feature_stub) { migration_stub(:MiqRolesFeature) }
let(:miq_user_role_stub) { migration_stub(:MiqUserRole) }

let(:settings_change_stub) { migration_stub(:SettingsChange) }

migration_context :up do
it "deletes product features" do
features = described_class::FEATURE_NAMES.map do |feature|
miq_product_feature_stub.find_or_create_by!(:identifier => feature)
end
features << miq_product_feature_stub.create!(:identifier => "other_feature")

role = miq_user_role_stub.create!(:name => "role1")
role_features = features.map do |f|
miq_roles_feature_stub.create!(:miq_user_role_id => role.id, :miq_product_feature_id => f.id)
end
other_role_feature = role_features.last

expect(miq_roles_feature_stub.count).to eq(features.length)

migrate

expect(miq_roles_feature_stub.count).to eq(1)
expect(miq_roles_feature_stub.all).to eq([other_role_feature])
expect(miq_product_feature_stub.where(:identifier => "other_feature").count).to eq(1)
expect(miq_product_feature_stub.where(:identifier => "collect_logs").count).to eq(0)
end

it "deletes settings" do
keep = settings_change_stub.create!(:key => "/log/level", :value => "debug")
to_delete = settings_change_stub.create!(:key => "/log/collection/ping_depot", :value => "false")

migrate

expect(settings_change_stub.count).to eq(1)
expect(settings_change_stub.first).to eq(keep)
end
end
end
1 change: 0 additions & 1 deletion spec/support/table_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ load_balancer_pool_member_pools
load_balancer_pool_members
load_balancer_pools
load_balancers
log_files
metric_rollups_01
metric_rollups_02
metric_rollups_03
Expand Down