amatsuda/database_rewinder
amatsuda/database_rewinder has 825 GitHub stars and 92 forks. Star changes are not measured yet. Last checked 2026-11-09 06:49 UTC. Last push 2025-07-23.
minimalist's tiny and ultra-fast database cleaner
What you can do
- Cleans up tables via DELETE SQL. No other strategies are implemented ATM
- Supports multiple databases
- Runs extremely fast :dash:
측정된 스타 증가
- in 24h
- 업데이트 지연
- in 7 days
- 업데이트 지연
- in 15 days
- 업데이트 지연
- in 1 month
- 업데이트 지연
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalDatabaseRewinder
database_rewinder is a minimalist's tiny and ultra-fast database cleaner.
Features
- Cleans up tables via DELETE SQL. No other strategies are implemented ATM
- Supports multiple databases
- Runs extremely fast :dash:
Why is it fast?
database_rewinder memorizes every table name into which INSERT SQL was performed during each test case.
Then it executes DELETE SQL only against these tables when cleaning.
So, the more number of tables you have in your database, the more benefit you will get.
Also, database_rewinder joins all DELETE SQL statements and casts it in one DB server call.
Credit
This strategy was originally devised and implemented by Shingo Morita (@eudoxa) at COOKPAD Inc.
Supported versions
ActiveRecord 4.2, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, 7.1, 7.2 (edge)
Ruby 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3 (trunk)
Installation
Add this line to your Gemfile's :test group:
gem 'database_rewinder'
And then execute:
$ bundle
Usage
Basic configuration
Do clean in after(:each). And do clean_all or clean_with in before(:suite) if you'd like to.
RSpec.configure do |config|
config.before(:suite) do
DatabaseRewinder.clean_all
# or
# DatabaseRewinder.clean_with :any_arg_that_would_be_actually_ignored_anyway
end
config.after(:each) do
DatabaseRewinder.clean
end
end
Dealing with multiple DBs
You can configure multiple DB connections to tell DatabaseRewinder to cleanup all of them after each test.
In order to add another connection, use DatabaseRewinder[] method.
RSpec.configure do |config|
config.before(:suite) do
# simply give the DB connection names that are written in config/database.yml
DatabaseRewinder['test']
DatabaseRewinder['another_test_db']
# you could give the DB name with connection: key if you like
DatabaseRewinder[connection: 'yet_another_test_db']
# or with a meaningless something first, then {connection: DB_NAME} as the second argument (DatabaseCleaner compatible)
DatabaseRewinder[:active_record, connection: 'an_active_record_db']
DatabaseRewinder.clean_all
end
config.after(:each) do
DatabaseRewinder.clean
end
end
MySQL + use_transactional_tests Specific Problems
database_rewinder tries to create a new DB connection for deletion when you're running tests on MySQL.
You would occasionally hit some weird errors (e.g. query execution timeout) because of this, especially when your tests are run with the use_transactional_tests option enabled (which is Rails' default).
1. Properly understand what use_transactional_tests means, and consider turning it off
use_transactional_tests is the option that surrounds each of your test case with a DB transaction to roll back all your test data after each test run.
So far as this works properly, you won't really need to use database_rewinder.
However, this simple mechanism doesn't work well when you're running integration tests with capybara + js mode.
In cases of this situation, bundle database_rewinder and add the following configuration.
RSpec.configure do |config|
config.use_transactional_tests = false
...
end
2. Cleaning with multiple: false option
If you're really sure you need to keep using transactional tests + database_rewinder for some reason, then explicitly pass in multiple: false option to DatabaseRewinder.clean_all and DatabaseRewinder.clean invocations as follows. Note that you won't be able to get full performance merit that database_rewinder provides though.
RSpec.configure do |config|
config.before :suite do
DatabaseRewinder.clean_all multiple: false
end
config.after :each do
DatabaseRewinder.clean multiple: false
end
end
Pro Tip
database_rewinder is designed to be almost compatible with database_cleaner. So the following code will probably let your existing app work under database_rewinder without making any change on your configuration.
DatabaseCleaner = DatabaseRewinder
Contributing
Send me your pull requests.
관련 프로젝트 살펴보기
Asabeneh/30-Days-Of-Python
30 Days of Python 프로그래밍 챌린지는 Python 프로그래밍 언어를 30일 동안 배우기 위한 단계별 가이드입니다. 이 챌린지는 100일 이상 걸릴 수 있습니다. 자신의 속도에 맞춰 진행하세요. 다음 동영상도 도움이 될 수 있습니다: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,486 스타grafana/grafana
개방적이고 조합 가능한 옵저버빌리티 및 데이터 시각화 플랫폼입니다. Prometheus, Loki, Elasticsearch, InfluxDB, Postgres 등 여러 소스의 메트릭, 로그, 트레이스를 시각화합니다.
77,790 스타redis/redis
실시간 데이터 기반 애플리케이션을 구축하는 개발자에게 Redis는 가장 선호되고, 가장 빠르며, 기능이 가장 풍부한 캐시, 데이터 구조 서버이자 문서 및 벡터 쿼리 엔진입니다.
77,332 스타apache/superset
Apache Superset는 데이터 시각화 및 데이터 탐색 플랫폼입니다.
75,455 스타