database_rewinder
DatabaseRewinder is a lightweight Ruby gem that cleans up test database state by tracking which tables were modified during each test and only deleting from those tables. It supports Rails, multiple databases, and is designed to be a faster, simpler alternative to DatabaseCleaner.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | amatsuda/database_rewinder |
| Owner | amatsuda |
| Primary language | Ruby |
| License | MIT — OSI-approved |
| Stars | 826 |
| Forks | 92 |
| Open issues | 16 |
| Latest release | Unknown |
| Last updated | 2025-07-23 |
| Source | https://github.com/amatsuda/database_rewinder |
What database_rewinder is
DatabaseRewinder hooks into ActiveRecord to track INSERT operations per test, then batches DELETE statements into a single database call to clean only modified tables. It supports Rails 4.2–7.2, Ruby 2.4–3.3, and multiple database connections with optional transactional-test compatibility via a `multiple: false` flag.
Get the database_rewinder source
Clone the repository and explore it locally.
git clone https://github.com/amatsuda/database_rewinder.gitcd database_rewinder# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Requires explicit RSpec configuration in `before(:suite)` and `after(:each)` hooks; copy-paste code from README is straightforward but non-standard.
- MySQL users must choose between disabling `use_transactional_tests` (recommended) or accepting reduced performance with `multiple: false` option.
- INSERT tracking is automatic but only effective if all test setup goes through INSERT SQL; raw SQL fixtures or bulk-load tools may not be tracked.
- Verify ActiveRecord and Ruby version compatibility (4.2–7.2 and 2.4–3.3 stated as supported); test in CI before adopting.
- The `DatabaseCleaner = DatabaseRewinder` compatibility alias allows drop-in replacement but does not guarantee behavioral parity for edge cases.
When to avoid it — and what to weigh
- You already use transactional tests successfully — If `use_transactional_tests = true` works for your test suite, it is simpler and faster; DatabaseRewinder adds complexity without benefit.
- You need advanced cleaning strategies — DatabaseRewinder only implements DELETE; if your tests require truncation, sequential resets, or non-SQL cleanup, use DatabaseCleaner or custom solutions.
- MySQL with transactional tests enabled — The README documents potential timeout and connection issues when combining `use_transactional_tests = true` with MySQL; workarounds reduce performance gains.
- You require recent security or feature patches — No releases since project creation; latest code is in main branch. Active development status unclear despite recent Git activity.
License & commercial use
MIT License. Permissive; allows commercial use, modification, and distribution with attribution and no warranty.
MIT is a permissive OSI license that explicitly permits commercial use and modification. No proprietary restrictions or commercial license required. Verify your legal review process for third-party dependency acceptance.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Moderate |
| Documentation | Adequate |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Good |
| Assessment confidence | High |
No documented security audit or vulnerability history. DELETE-based cleanup is lower-risk than truncation or transaction rollback. Verify that test database credentials and connection pooling do not leak or collide across test workers in parallel CI environments. No explicit statement on handling of sensitive data in test cleanup.
Alternatives to consider
DatabaseCleaner
Industry standard; supports truncate, delete, and transaction strategies; mature release history and extensive adoption. Trade-off: slower on large schemas but more flexible.
Rails transactional tests (use_transactional_tests = true)
Built-in; no dependency; simplest for unit and integration tests that do not require headless browsers. Trade-off: fails with Capybara JS mode and multi-threaded scenarios.
Custom test fixtures + database snapshots
Fine-grained control; supports non-SQL cleanup and complex data graphs. Trade-off: high maintenance burden and slower than specialized cleaners.
Build on database_rewinder with DEV.co software developers
DatabaseRewinder is best suited for Rails projects with large schemas or Capybara integration tests. Evaluate against DatabaseCleaner and transactional tests for your specific test patterns. Contact us for guidance on test infrastructure optimization.
Talk to DEV.coRelated open-source tools
Surfaced by semantic similarity across the DEV.co open-source index.
Related on DEV.co
Explore the category and the services that help you build with it.
database_rewinder FAQ
Is DatabaseRewinder safe to use in production?
Does it work with non-Rails projects?
Why does the README recommend turning off use_transactional_tests?
How much faster is it than DatabaseCleaner?
Work with a software development agency
Adopting database_rewinder is usually one piece of a larger software development effort. As a software development agency, DEV.co provides software development services and web development expertise — pairing senior software developers and web developers with your team to design, build, and operate open-source testing software in production.
Optimize Your Test Suite
DatabaseRewinder is best suited for Rails projects with large schemas or Capybara integration tests. Evaluate against DatabaseCleaner and transactional tests for your specific test patterns. Contact us for guidance on test infrastructure optimization.