gregnavis/active_record_doctor
65.8
Adequate · 19 September 2026
2.1k
lines of production code
Ruby
primary language
1
measurement over time
What this system is
Active Record Doctor is a standalone Ruby gem that analyzes database schemas to detect common anti-patterns and health issues, such as missing indexes, invalid constraints, and mismatched types. It operates independently of the full Rails framework by depending only on ActiveRecord, allowing it to function in non-Rails projects via a Rake task. The system provides a configurable suite of detectors to identify problems and includes a generator to automatically create migrations for fixing missing foreign key indexes.
How it got here
2016 — v2.0 refactor and decoupling
13 changes.
The project underwent a major architectural overhaul to v2.0, decoupling from the full Rails framework to depend solely on Active Record and restructuring its internal task system into a modular detector-based configuration. This period also saw the expansion of database health checks with numerous new detectors, the addition of a migration generator, and the modernization of the test suite to support multiple database adapters.
2021–2023 — Imperative architecture and configuration overhaul
7 changes.
The project underwent a significant architectural refactoring, migrating detectors to a new imperative base class with standardized configuration and logging. This period also introduced a robust, project-wide configuration system with default settings and expanded test coverage to ensure reliability across new and existing features.
Features
Add generator for creating missing foreign key indexes
Users can now run \rails generate active\_record\_doctor:add\_indexes PATH\ to automatically create migration files that add missing indexes to tables. The generator reads a file containing index descriptions, creates separate migration files for each table with unique timestamps to avoid conflicts, and ensures index names respect the database's length limits.
lib/generators · high confidence
Add support for ActiveRecord 8.0 and SQLite
The gemfiles now include a dedicated configuration for ActiveRecord 8.0, expanding compatibility beyond the previously supported 7.0, 7.1, and 7.2 versions. Additionally, SQLite support has been added to the 7.0, 7.1, and 7.2 gemfiles, allowing users to utilize SQLite as a database adapter alongside PostgreSQL and MySQL.
gemfiles · high confidence
Removals
Removal of unindexed foreign keys task implementation
The implementation file for the \unindexed\_foreign\_keys\ task has been deleted from the codebase. This removes the specific logic that scanned database tables for columns ending in \\_id\ that lacked corresponding indexes, excluding the \schema\_migrations\ table. Users relying on this specific rake task to identify unindexed foreign keys will no longer have access to this functionality through this file.
_lib/active\_record\doctor/tasks · high confidence
Remove IOPrinter class
The IOPrinter class, which was responsible for formatting and outputting unindexed foreign key information to a specified IO stream, has been removed from the codebase.
_lib/active\_record\doctor/printers · high confidence
Behavioural changes
Active Record Doctor detectors refactored into a new imperative architecture
The \lib/active\_record\_doctor/detectors\ directory has been completely rewritten to use a new base class (\Base\) and an imperative detection style. This change introduces a standardized configuration system (supporting global and local settings like \ignore\_models\ and \ignore\_columns\), structured logging, and a consistent problem-reporting mechanism across all detectors. Existing detectors such as \extraneous\_indexes\, \missing\_presence\_validation\, and \unindexed\_foreign\_keys\ have been migrated to this new framework, ensuring consistent behavior and easier maintenance while preserving their core detection logic.
_lib/active\_record\doctor/detectors · high confidence
Decoupling from Rails and expanding detection capabilities
The library has been refactored to remove its hard dependency on Rails, allowing it to function in non-Rails projects via a dedicated rake task integration. This change also significantly expands the scope of database analysis by introducing a suite of new detectors, including checks for missing presence validations, incorrect length validations, mismatched foreign key types, tables without primary keys or timestamps, and unindexed foreign keys.
lib · high confidence
Introduces configurable default settings and a project-based configuration system
The tool now ships with a \default.rb\ configuration file that explicitly defines the enabled state and default options for all detectors (such as \incorrect\_length\_validation\, \table\_without\_primary\_key\, and \table\_without\_timestamps\) and global settings like ignored tables (including Active Storage and Action Text). A new configuration loader allows users to provide a project-specific config file that merges with these defaults, enabling granular control over which detectors run and how they behave without requiring users to redefine every option from scratch.
_lib/active\_record\doctor/config · high confidence
Rails integration and expanded database health checks
The Rake task integration for Rails has been updated to automatically eager-load the application environment before running checks, ensuring accurate detection in a loaded context. The scope of database health analysis has expanded significantly to include detection of unindexed foreign keys, extraneous indexes, missing foreign keys, undefined table references, unindexed soft-delete columns, missing unique indexes, missing presence validations, missing non-null constraints, incorrect boolean presence validations, incorrect dependent options, short primary key types, and mismatched foreign key types.
lib/tasks · high confidence
Rake task now supports project-wide configuration and debug logging
The new Rake task integration allows users to configure active\_record\_doctor via a project-wide \.active\_record\_doctor.rb\ file (with backward compatibility for the legacy \.active\_record\_doctor\ file, which now triggers a deprecation warning). Users can also enable verbose debug output by setting the \ACTIVE\_RECORD\_DOCTOR\_DEBUG\ environment variable, and the task structure now supports explicit dependency injection and custom setup hooks for more flexible integration into existing Rake workflows.
_lib/active\_record\doctor/rake · high confidence
active\_record\_doctor v2.0.1: Major refactor and configuration overhaul
This release introduces a significant architectural shift in how the tool is structured and configured. The internal task system has been renamed to 'detectors' (lib/active\_record\_doctor/detectors.rb), and the rake task file has been renamed from active\_record\_doctor\_task.rake to active\_record\_doctor.rake. A new configuration system (lib/active\_record\_doctor/config.rb) allows for merging global and detector-specific settings, supported by a comprehensive error handling module (lib/active\_record\_doctor/errors.rb) that provides detailed user messages for configuration issues like missing files, unrecognized detectors, or duplicate settings. The runner (lib/active\_record\_doctor/runner.rb) now explicitly manages config, logger, and I/O injection, and the help system (lib/active\_record\_doctor/help.rb) has been updated to reflect the new configuration options. The version has been bumped to 2.0.1, indicating a major version change likely involving breaking changes to the configuration API and internal structure.
_lib/active\_record\doctor · high confidence
Test coverage
Added tests for AddIndexesGenerator; Added tests for configuration loading and simplified test infrastructure; Added tests for configuration merging and runner execution; Expanded test coverage for Active Record Doctor detectors; Introduce RuboCop linting and multi-database test suite; Remove unused SpyPrinter test support class; Removed Rails dummy application scaffolding; Removed test for unindexed foreign keys task; Removed tests for the IO printer.
Dependencies
Upgrade Active Record dependency to version 7.0+ and update development tooling
The gem now requires Active Record 7.0.0 or newer, dropping support for older versions, and updates the homepage URL. Development dependencies have been refreshed to include specific versions of minitest-fork\_executor, mysql2, pg, railties, rake, rubocop, sqlite3, and transient\_record, while the runtime dependency on the full 'rails' gem has been replaced with a direct dependency on 'activerecord'.
(dependencies) · high confidence
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Baseline
- First survey — no prior run to compare against. CAI 66.
Lenses
- Code Health 99
- Architecture 95
- Maturity 51
- Readiness 62
- Security 94
Changes since last survey
- 283 commits — 228 feature/other, 55 fixes
By area
- lib/active_record_doctor — 132 commits
- (root) — 94 commits
- test/active_record_doctor — 12 commits
- .github/workflows — 10 commits
- lib/generators — 9 commits
- test/dummy — 9 commits
- (repo) — 5 commits
- gemfiles/Gemfile.rails-4.2.x — 2 commits
- test/setup.rb — 2 commits
- gemfiles/Gemfile.activerecord-7.0.x — 1 commit
- gemfiles/Gemfile.rails-5.2.x — 1 commit
- gemfiles/Gemfile.rails-6.0.x — 1 commit
- lib/active_record_doctor.rb — 1 commit
- test/active_record_doctor_test.rb — 1 commit
- test/model_factory.rb — 1 commit
- test/support — 1 commit
- test/test_helper.rb — 1 commit
Notable commits
- fix: Fix AddIndexesGenerator migration versioning
- fix: Fix CI
- fix: Fix Gemfile path in CI
- fix: Fix Markdown in CHANGELOG.md
- fix: Fix README.md typo
- fix: Fix Rails 6.0 deps
- fix: Fix Travis CI configuration
- fix: Fix a reference to unindexed_deleted_at
- fix: Fix a syntax error in io_printer.rb
- fix: Fix a warning about an overshadowed variable
- fix: Fix active_record_doctor:add_index in Rails 6
- fix: Fix build status (#174)
- fix: Fix checking for expression indexes support (#196)
- fix: Fix configuration option key in README (#190)
- fix: Fix dropping test tables on MySQL
- fix: Fix each_model for existing tables
- fix: Fix extraneous_indexes on unique indexes
- fix: Fix ignore_columns in missing_unique_indexes
- fix: Fix incorrect_boolean_presence_validation
- fix: Fix incorrect_dependent_option documentation
- …and 263 more
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
gregnavis/active_record_doctor was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 19 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit c42816d5467df19800c46b3cca5fbe9827848fef — the exact code this score is about.
- Scored under rubric-2026.09.15 — the same rubric and the same method as every other entry in this index.
- Measured by watchdog.canine.dev using codehealth-analyzer preprod-13a154b7f5d1.