forked from ManageIQ/manageiq-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete invalid nil timestamp event streams
Until ManageIQ/manageiq-providers-kubernetes#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.
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
db/migrate/20230830134742_delete_nil_timestamp_event_streams.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
16 changes: 16 additions & 0 deletions
16
spec/migrations/20230830134742_delete_nil_timestamp_event_streams_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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.pluck(:id, :timestamp).flatten).to eq([good.id, good.timestamp]) | ||
end | ||
end | ||
end |