diff --git a/lib/data_fixup/fix_audit_log_uuid_indexes.rb b/lib/data_fixup/fix_audit_log_uuid_indexes.rb index 7d248fceb89..15c8f252b14 100644 --- a/lib/data_fixup/fix_audit_log_uuid_indexes.rb +++ b/lib/data_fixup/fix_audit_log_uuid_indexes.rb @@ -169,6 +169,11 @@ module DataFixup @start_time ||= Time.new(2014, 6, 14) end + # The date the audit logs were enabled. + def end_time + @end_time ||= Time.new(2014, 8, 20) + end + def index @index end @@ -229,11 +234,12 @@ module DataFixup need_tombstone = [] updates = [] oldest_bucket = index.bucket_for_time(start_time) + newest_bucket = index.bucket_for_time(end_time) # Check each row to see if we need to update it or inspect it. rows.each do |row| row = format_row(row) - next if row['bucket'] < oldest_bucket + next if row['bucket'] < oldest_bucket || row['bucket'] > newest_bucket current_id, timestamp, key = extract_row_keys(index, row) actual_id = query_corrected_id(current_id, timestamp) if actual_id.nil? diff --git a/spec/lib/data_fixup/fix_audit_log_uuid_indexes_spec.rb b/spec/lib/data_fixup/fix_audit_log_uuid_indexes_spec.rb index 3c47c9d7810..2cacf9d95f2 100644 --- a/spec/lib/data_fixup/fix_audit_log_uuid_indexes_spec.rb +++ b/spec/lib/data_fixup/fix_audit_log_uuid_indexes_spec.rb @@ -51,6 +51,8 @@ describe DataFixup::FixAuditLogUuidIndexes do # Truncate the mapping and last batch tables. @database.execute("TRUNCATE #{DataFixup::FixAuditLogUuidIndexes::MAPPING_TABLE}") @database.execute("TRUNCATE #{DataFixup::FixAuditLogUuidIndexes::LAST_BATCH_TABLE}") + + DataFixup::FixAuditLogUuidIndexes::IndexCleaner.any_instance.stubs(:end_time).returns(Time.now + 1.month) end def check_event_stream(event_id, stream_table, expected_total) @@ -245,4 +247,21 @@ describe DataFixup::FixAuditLogUuidIndexes do expect(events.first.attributes['created_at'].to_i).to eq first_event_at end + + it "should skip records after the bug fix was released" do + # Create bad data + stream_checks = {} + stream_checks['grade_changes'] = corrupt_grade_changes + stream_checks['courses'] = corrupt_course_changes + stream_checks['authentications'] = corrupt_authentications + + DataFixup::FixAuditLogUuidIndexes::IndexCleaner.any_instance.stubs(:end_time).returns(Time.now - 1.month) + + DataFixup::FixAuditLogUuidIndexes::IndexCleaner.any_instance.expects(:create_tombstone).never + DataFixup::FixAuditLogUuidIndexes::IndexCleaner.any_instance.expects(:create_index_entry).never + DataFixup::FixAuditLogUuidIndexes::IndexCleaner.any_instance.expects(:delete_index_entry).never + + # Run Fix + DataFixup::FixAuditLogUuidIndexes::Migration.run + end end