You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SeededDeletion Strategy for DatabaseCleaner ActiveRecord #128
Because I had a similar use case as described in #31, I've developed a solution for running UI tests with seeded data while only cleaning records created during testing.
When start is called, it captures the maximum ID for each table
When clean is called, it only deletes rows with IDs greater than the captured maximums
This effectively preserves all pre-existing seed data while cleaning up records created during test execution.
Details
Extends the standard Deletion strategy
Currently tested with PostgreSQL (though adaptable to other databases)
Uses SQL to identify tables with ID columns
Handles edge cases like tables without ID columns
The current implementation is functional but has room for optimization:
Reduce the need to visit each table in separate queries
Add support for other databases
Improve performance for larger databases
If it gets fast enough, the default implementation could add itself in the before/after in typical test frameworks such as minitest/rspec/cypress/etc.
Integration Question
Would the DatabaseCleaner team consider incorporating this strategy into the active_record repository, or should it remain as a standalone extension? I believe this addresses a common use case for teams working with seeded test environments.
Activity
jrafanie commentedon Oct 16, 2025
If there's interest, I can propose a PR to add it.