Skip to content

Commit 00aeafd

Browse files
authored
Merge pull request #821 from Fryguy/drop_log_collection2
Drop miq_schedules.file_depot_id
2 parents b6354e0 + c179767 commit 00aeafd

4 files changed

+45
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class DropMiqScheduleFileDepotRecords < ActiveRecord::Migration[7.2]
2+
class MiqSchedule < ActiveRecord::Base
3+
include ActiveRecord::IdRegions
4+
end
5+
6+
def up
7+
say_with_time("Dropping schedules attached to file_depot records") do
8+
MiqSchedule.in_my_region.where.not(:file_depot_id => nil).delete_all
9+
end
10+
end
11+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class DropMiqScheduleFileDepot < ActiveRecord::Migration[7.2]
2+
def change
3+
remove_column :miq_schedules, :file_depot_id, :bigint
4+
end
5+
end

spec/migrations/20251104153211_drop_log_collection_configuration_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ class MiqUserRole < ActiveRecord::Base; end
3535
end
3636

3737
it "deletes settings" do
38-
keep = settings_change_stub.create!(:key => "/log/level", :value => "debug")
38+
to_keep = settings_change_stub.create!(:key => "/log/level", :value => "debug")
3939
to_delete = settings_change_stub.create!(:key => "/log/collection/ping_depot", :value => "false")
4040

4141
migrate
4242

4343
expect(settings_change_stub.count).to eq(1)
44-
expect(settings_change_stub.first).to eq(keep)
44+
expect(settings_change_stub.first).to eq(to_keep)
45+
expect { to_delete.reload }.to raise_error(ActiveRecord::RecordNotFound)
4546
end
4647
end
4748
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require_migration
2+
3+
class DropMiqScheduleFileDepotRecords < ActiveRecord::Migration[7.2]
4+
class FileDepot < ActiveRecord::Base
5+
self.inheritance_column = :_type_disabled
6+
end
7+
end
8+
9+
describe DropMiqScheduleFileDepotRecords do
10+
let(:file_depot_stub) { migration_stub(:FileDepot) }
11+
let(:miq_schedule_stub) { migration_stub(:MiqSchedule) }
12+
13+
migration_context :up do
14+
it "deletes schedules associated to file depots" do
15+
file_depot = file_depot_stub.create!(:name => "my_file_depot")
16+
to_delete = miq_schedule_stub.create!(:name => "my_file_depot schedule", :file_depot_id => file_depot.id)
17+
to_keep = miq_schedule_stub.create!(:name => "other schedule", :file_depot_id => nil)
18+
19+
migrate
20+
21+
expect(miq_schedule_stub.count).to eq(1)
22+
expect(miq_schedule_stub.first).to eq(to_keep)
23+
expect { to_delete.reload }.to raise_error(ActiveRecord::RecordNotFound)
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)