Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

SeededDeletion Strategy for DatabaseCleaner ActiveRecord

Open
#128 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
postgresql, rails, ruby
Domain
databases, testing

Research direction

Review the linked lib/database_cleaner/active_record/seeded_deletion.rb implementation and compare it with the repository's existing ActiveRecord deletion strategy and tests. Determine whether the strategy belongs in this repository or remains an extension, and define done as an agreed integration or documentation decision with appropriate database coverage.

Written by the indexing model from the issue text.

Description

Hello,

Because I had a similar use case as described in https://github.com/DatabaseCleaner/database_cleaner-active_record/issues/31, I've developed a solution for running UI tests with seeded data while only cleaning records created during testing.

The SeededDeletion Strategy preserves seed data while removing test-generated records: database_cleaner-activerecord-seeded_deletion.

How It Works

The SeededDeletion class implements simple logic:

  1. When start is called, it captures the maximum ID for each table
  2. 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

Usage Example
DatabaseCleaner[:active_record].strategy = DatabaseCleaner::ActiveRecord::SeededDeletion.new
Future Improvements

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.

Thank you.

Dominant language
Ruby
Stars
76
Forks
76
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DatabaseCleaner/database_cleaner-active_record

All issues in DatabaseCleaner/database_cleaner-active_record

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.