// the find
amatsuda/database_rewinder
minimalist's tiny and ultra-fast database cleaner
database_rewinder is a lightweight test database cleaner for Ruby/Rails that replaces DatabaseCleaner's truncation strategy with targeted DELETEs on only the tables touched during a test. It's for Rails teams running RSpec/Minitest suites who want faster teardown than full-table truncation, especially on schemas with many tables.
The core trick is legitimately smart: it hooks ActiveRecord's insert path to remember which tables got written to per test, then issues DELETE only against those, joined into a single server call instead of one round trip per table. That means cleanup cost scales with what the test actually touched, not total schema size - a real win on apps with hundreds of tables. It also supports multiple DB connections out of the box and is a near drop-in replacement for database_cleaner (DatabaseCleaner = DatabaseRewinder works), so migration cost is low. The version matrix (AR 4.2 through 7.2, Ruby 2.4 through 3.3) shows it's been kept alive across a decade of Rails changes.
It does exactly one thing - DELETE-based cleanup - with no truncation or transactional strategy, so if DELETE performance degrades (foreign keys, triggers, cascades) you have no fallback within the gem. The whole mechanism depends on monkey-patching ActiveRecord's insert internals (active_record_monkey.rb), which is inherently fragile against AR version changes and is exactly why the compatibility matrix needs constant upkeep. The README itself flags that MySQL plus Rails' default use_transactional_tests can produce query timeouts from the extra connection database_rewinder opens, with the suggested fixes being 'turn off transactional tests' or 'give up most of the speed gain' - that's a real rough edge, not a hypothetical one. And it's AR/Rails-specific; there's no support for Sequel, ROM, or other Ruby ORMs.