-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #704 from jrafanie/delete_nil_timestamp_event_streams
Delete invalid nil timestamp event streams
- Loading branch information
Showing
2 changed files
with
29 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 |
18 changes: 18 additions & 0 deletions
18
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,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 |