gregnavis/active_record_doctor
68.1
Adequate · 6 November 2026
2.2k
lines of production code
Ruby
primary language
4
measurements over time
What this system is
Active Record Doctor is a standalone Ruby library that analyzes database schemas and model configurations to identify structural issues and anti-patterns. It provides a suite of detectors for problems such as missing indexes, incorrect foreign keys, and validation errors, accessible via a Rake task or command-line interface. The system supports configurable project-wide settings and includes a generator to automatically create migrations for fixing detected issues.
How it got here
2016 — Rails decoupling and v2.1.0 restructuring
13 changes.
The project underwent a major internal restructuring to version 2.1.0, decoupling from the full Rails framework to depend only on Active Record and expanding its database health check capabilities. This period involved removing legacy components like the IOPrinter and unindexed foreign keys task, while introducing new detectors, a code generator for missing indexes, and a modernized, standalone test infrastructure.
2021–2024 — Imperative refactoring and configuration overhaul
7 changes.
The codebase underwent a significant structural refactoring, shifting detectors to a unified imperative class hierarchy and introducing a robust, project-wide configuration system with default settings. This period also expanded test coverage for the new architecture and added compatibility for Rails 8.0 and 8.1 alongside ActiveRecord 7.2.
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 on foreign key columns. The generator reads a file containing index descriptions, creates separate migration files for each table with unique timestamps, and ensures generated index names respect the database's length limits.
lib/generators · high confidence
Introduces configurable default settings and project-based configuration loading
Users can now customize the behavior of ActiveRecord Doctor detectors via a project-specific configuration file. A new default configuration file defines the baseline settings for all detectors (such as \extraneous\_indexes\, \missing\_foreign\_keys\, and \table\_without\_primary\_key\), including options to ignore specific tables, models, or columns. The configuration loader now supports merging user-provided settings with these defaults, allowing users to enable/disable detectors, adjust ignore lists, and modify detector-specific options without modifying the library's source code.
_lib/active\_record\doctor/config · high confidence
Removals
Removal of IOPrinter class
The \IOPrinter\ class, previously responsible for formatting and outputting unindexed foreign key information to standard output, has been removed from the codebase.
_lib/active\_record\doctor/printers · high confidence
Removal of unindexed foreign keys task implementation
The implementation file for the \UnindexedForeignKeys\ 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, effectively removing this diagnostic capability from the \active\_record\_doctor\ tool.
_lib/active\_record\doctor/tasks · high confidence
Behavioural changes
Active Record Doctor detectors refactored into a new imperative class structure
The library's detection logic has been restructured around a new \Base\ detector class that standardizes configuration, logging, and problem reporting. This change introduces a suite of updated and new detectors—including \ExtraneousIndexes\, \IncorrectBooleanPresenceValidation\, \IncorrectDependentOption\, \IncorrectLengthValidation\, \MismatchedForeignKeyType\, \MissingForeignKeys\, \MissingNonNullConstraint\, \MissingPresenceValidation\, \MissingUniqueIndexes\, \ShortPrimaryKeyType\, \TableWithoutPrimaryKey\, \TableWithoutTimestamps\, \UndefinedTableReferences\, \UnindexedDeletedAt\, \UnindexedForeignKeys\, and \UnusedTables\—which now operate using this unified imperative style to identify schema and model issues.
_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 set of available database checks, introducing new detectors for issues such as unused tables, tables missing primary keys or timestamps, mismatched foreign key types, and incorrect validation lengths, alongside support for project-wide configuration files.
lib · high confidence
Introduces RuboCop for code style enforcement and updates build tasks
The project now enforces code style using RuboCop, replacing the previous RDoc-based documentation generation. A new \.rubocop.yml\ configuration file defines specific style rules (such as double quotes for strings and bracket-style arrays) and disables checks that are incompatible with the supported Ruby versions or the project's complexity metrics. The \Rakefile\ has been updated to invoke RuboCop during the default test task and to run tests against PostgreSQL, MySQL, and SQLite adapters, while \.gitignore\ has been updated to exclude gem artifacts and lock files.
(repo-wide) · 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 version 2.1.0
The library has been updated to version 2.1.0. This release includes a complete internal restructuring of the codebase, introducing new modules for configuration management, detector discovery, error handling, and hierarchical logging, while renaming the previous tasks module to a logger module and updating the associated Rails railtie to load the new rake task file.
_lib/active\_record\doctor · high confidence
Test coverage
Added tests for AddIndexesGenerator; Added tests for configuration loading and refactored test infrastructure; Added tests for configuration merging and runner execution; Added tests for new and updated Active Record Doctor detectors; 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
Add support for Rails 8.0, 8.1, and ActiveRecord 7.2 with SQLite and logging
The gemfiles now include configurations for ActiveRecord 7.2.x, 8.0.x, and 8.1.x, enabling compatibility with Rails 8.0 and 8.1. The 7.2.x configuration adds support for SQLite and includes the \logger\ gem, while the 8.0.x and 8.1.x configurations focus on PostgreSQL and MySQL drivers.
gemfiles · high confidence
Upgrade to Rails 7+ and modernize dependencies
The gem now requires Active Record 7.0.0 or newer, dropping support for older Rails versions. The runtime dependency on the full 'rails' gem has been replaced with a specific dependency on 'activerecord'. Development dependencies have been updated to include modern testing tools (minitest, minitest-fork\_executor, minitest-mock), database drivers (pg, mysql2, sqlite3), and rubocop, while removing the legacy sqlite3 development dependency and the temping gem.
(dependencies) · high confidence
Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Score
- CAI 67 → 68 (+1.5)
- Rubric changed (rubric-2026.10.5 → rubric-2026.11.2) — scores are not directly comparable.
Lenses
- Code Health 75 → 75 (+0.0)
- Architecture 96 → 96 (+0.0)
- Maturity 57 → 61 (+3.6)
- Readiness 65 → 65 (+0.0)
- Security 95 → 92 (-3.1)
Resolved (4)
- Ambiguous configuration loading strategy. configure takes a block (likely for in-memory DSL configuration), while load_config and load_config_with_defaults take a path. It is unclear if load_config and load_config_with_defaults are distinct operations or if one is a wrapper of the other with different default behavior. Furthermore, it is unclear if these methods are mutually exclusive or if they compose (e.g., does calling load_config after configure override it?).
- Documentation: no contributor guidance (README.md)
- Duplicate method signatures with different arities. Base.run is defined twice: once with (args, kwargs, block) and once with no arguments. This suggests either an overload that isn't clearly distinguished by name, or a copy-paste error in the API surface definition. If they serve different purposes (e.g., one for internal execution, one for public API), they should have distinct names.
- Off-boarding risk: anonymized user #1
New (1)
- Off-boarding risk: anonymized user #1
Written by cca.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 6 November 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit df5265fea6f76dae826d7df2c1edf84e5f51e122 — the exact code this score is about.
- Scored under rubric-2026.11.2 — the same rubric and the same method as every other entry in this index.
- Measured by Canine Code Analyzer (cca.canine.dev) using cca measure-2026.11.2+preprod-5c4e66d9318b.