From 2ba5fb106389018873745273f8490b266f3e604b Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Wed, 30 Aug 2023 10:06:37 -0400 Subject: [PATCH] Delete invalid nil timestamp event streams Until https://github.com/ManageIQ/manageiq-providers-kubernetes/pull/501 code lands, openshift events with nil timestamps will be added to event streams. These are invalid events and really mess up our queries since we timestamp is a lookup field and expected to use an index which doesn't happen when it's nil. --- ...34742_delete_nil_timestamp_event_streams.rb | 11 +++++++++++ ..._delete_nil_timestamp_event_streams_spec.rb | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 db/migrate/20230830134742_delete_nil_timestamp_event_streams.rb create mode 100644 spec/migrations/20230830134742_delete_nil_timestamp_event_streams_spec.rb diff --git a/db/migrate/20230830134742_delete_nil_timestamp_event_streams.rb b/db/migrate/20230830134742_delete_nil_timestamp_event_streams.rb new file mode 100644 index 000000000..b7c0a77d0 --- /dev/null +++ b/db/migrate/20230830134742_delete_nil_timestamp_event_streams.rb @@ -0,0 +1,11 @@ +class DeleteNilTimestampEventStreams < ActiveRecord::Migration[6.1] + class EventStream < ActiveRecord::Base + self.inheritance_column = :_type_disabled + end + + def up + say_with_time("Deleting event_streams with nil timestamp values") do + EventStream.where(:timestamp => nil).delete_all + end + end +end diff --git a/spec/migrations/20230830134742_delete_nil_timestamp_event_streams_spec.rb b/spec/migrations/20230830134742_delete_nil_timestamp_event_streams_spec.rb new file mode 100644 index 000000000..108ab1099 --- /dev/null +++ b/spec/migrations/20230830134742_delete_nil_timestamp_event_streams_spec.rb @@ -0,0 +1,18 @@ +require_migration + +describe DeleteNilTimestampEventStreams do + let(:event_stream_stub) { migration_stub(:EventStream) } + + migration_context :up do + it "removes nil timestamp events, leaving others" do + good = event_stream_stub.create!(:timestamp => Time.now.utc) + event_stream_stub.create!(:timestamp => nil) + + migrate + + expect(event_stream_stub.count).to eq(1) + expect(event_stream_stub.first.id).to eq(good.id) + expect(event_stream_stub.first.timestamp).to be_present + end + end +end