djezzzl/database_consistency
53.7
Adequate · 20 September 2026
5.9k
lines of production code
Ruby
primary language
1
measurement over time
What this system is
This system is a Ruby gem that analyzes Rails applications to detect and remediate inconsistencies between database schemas and application code. It provides a modular suite of checkers that validate associations, columns, indexes, enums, and validators against their database counterparts. The tool offers a CLI interface to generate reports, create TODO lists, and automatically produce migration files to fix detected issues.
How it got here
2018–2019 — Modular architecture and checker expansion
20 changes.
The project underwent a major architectural refactor, transitioning from a monolithic design to a modular system of processors, checkers, and writers. This period introduced a comprehensive suite of new consistency checks for columns, associations, and validators, alongside a new CLI and automated autofix capabilities. Support was expanded to include modern Rails versions (6–8) and multiple database adapters, with CI infrastructure migrated to Docker and Appraisals.
2020–2022 — autofix and consistency checks
12 changes.
The project expanded its database consistency capabilities by introducing new checkers for index redundancy, uniqueness, and enum type mismatches. It also added an autofix feature to automatically generate migrations for detected violations and implemented a concise simple output writer for reports. Comprehensive test coverage was added across multiple database adapters to ensure the reliability of these new features.
2023–2026 — Rails 7/8 support and schema checkers
5 changes.
This period focused on expanding framework compatibility by adding example applications for Rails 7 and Rails 8, alongside introducing new model consistency checkers for missing tables and view primary keys. The work also included enhancing the testing infrastructure with comprehensive coverage for unique index partials and autofix writer generators.
Features
Add Rails 6 example application with Zeitwerk and Webpacker support
A new Rails 6 example application has been added to the repository to serve as a testbed for the database consistency checker. This example is configured to use the Zeitwerk code loader and Webpacker for JavaScript asset management, providing a realistic environment to validate checker behavior against modern Rails conventions, including polymorphic associations and specific index configurations.
rails6-example · high confidence
Add Rails 8 example application
This change introduces a new \rails8-example\ directory containing a complete, scaffolded Rails 8 application. It serves as a reference implementation for the new framework version, featuring a production-ready Dockerfile, Kamal deployment configuration, and modern Rails 8 defaults such as \allow\_browser versions: :modern\ in the application controller, \primary\_abstract\_class\ for the base model, and configuration for Solid Cache, Solid Queue, and Solid Cable in production.
rails8-example · high confidence
Add enum type consistency checking
The library now includes a new EnumTypeChecker that validates whether the database column type for an enum matches the types of its defined values. This ensures that enum definitions are consistent with their underlying storage, preventing mismatches between string/integer values and their column types.
_lib/database\_consistency/checkers/enum\checkers · high confidence
Added Rails 7 example application with multi-database support
This location introduces a complete Rails 7 example application scaffold, including configuration for multiple database connections (primary and secondary) via \config/database.yml\ and \SecondaryRecord\. The setup includes model definitions with various associations and validations, database migrations, and a \.database\_consistency.yml\ configuration file for the \database\_consistency\ tool to validate schema integrity. It also sets up the standard Rails 7 asset pipeline with Importmap, Stimulus, and Turbo.
rails7-example · high confidence
Autofix migration writers for database consistency issues
The \lib/database\_consistency/writers/autofix\ directory now includes a set of new classes and ERB templates that automatically generate Rails migrations to resolve specific database consistency violations. This feature adds writers for missing foreign keys, missing null constraints, redundant indexes, missing indexes on associations (including unique indexes for \has\_one\), and inconsistent column types. When these issues are detected, the system can now produce the corresponding migration files to fix them automatically.
_lib/database\consistency/writers/autofix · high confidence
Initial Rails 5.2 application scaffold
This change introduces the foundational structure for a new Rails 5.2 example application. It adds standard executable binstubs in \bin/\ (including \rails\, \bundle\, \rake\, \spring\, and \setup\) to manage the environment and dependencies. The \config/\ directory is populated with essential configuration files, such as \application.rb\ (configured with \config.load\_defaults 5.2\), environment-specific settings for development, test, and production, and initializers for assets, cookies, and security policies. It also includes default database (\database.yml\), cable (\cable.yml\), and storage (\storage.yml\) configurations, alongside encrypted credentials and a master key for secure secret management. Finally, it provides standard public assets, including error page templates (404, 422, 500) and static files.
rails-example/bin, rails-example/config, rails-example/public · high confidence
Initial Rails application scaffolding
The rails-example application has been initialized with the standard Rails directory structure and default configuration files. This includes the setup of the asset pipeline (JavaScript, CSS, and images), ActionCable for WebSocket support, and base classes for controllers, models, jobs, and mailers. The example also defines sample models (User, Company, Country, Admin) with various validations and associations to demonstrate framework features.
rails-example/app · high confidence
Initial Rails application scaffolding and configuration
The rails-example location now includes the foundational structure for a Rails application, featuring a Rakefile and config.ru to handle task loading and Rack-based server startup. Additionally, a .database\_consistency.yml configuration file has been added to define specific database integrity checks, such as index and constraint validations, for models like User, Country, Event, and Poll.
rails-example · high confidence
Initial database schema and seed data for the Rails example
The \rails-example/db\ directory now includes the foundational database structure for the application. This adds migrations to create \countries\, \users\, and \companies\ tables, along with a corresponding \schema.rb\ that defines the current database state (version 2018\_11\_12\_080414). The \users\ table includes specific constraints such as unique indexes on \slug\ and the combination of \name\ and \slug\, as well as foreign key relationships to \countries\. A \seeds.rb\ file is also provided to allow for initial data population.
rails-example/db · high confidence
Introduce database type mapping and factory for consistency checks
Added a new type-checking system to the database consistency library, including a Factory that instantiates type wrappers based on the database adapter (e.g., SQLite vs. others) and specific type classes (Base and Sqlite) that handle type normalization and compatibility checks. This enables more accurate detection of type mismatches in foreign keys by mapping database-specific types (like SQLite's integer sizes or PostgreSQL's serial/bigserial) to a common representation for comparison.
_lib/database\consistency/databases · high confidence
Introduces a new 'Simple' output writer for database consistency reports
The \lib/database\_consistency/writers/simple\ directory now provides a new reporting format that presents database consistency findings in a concise, single-line format. This writer includes a base class for handling colored terminal output and a comprehensive set of checkers covering association integrity (missing foreign keys, indexes, null constraints), data validation mismatches (enum values, length limits, numericality), and schema hygiene (redundant indexes, missing primary keys on views). Users will see these specific, actionable messages instead of the previous output style when this writer is selected.
_lib/database\consistency/writers/simple · high confidence
New column consistency checkers for Rails models
The library now includes a suite of new column checkers to detect schema and validation inconsistencies. These include PrimaryKeyTypeChecker (ensures primary keys use bigserial/bigint/uuid), ImplicitOrderingChecker (verifies implicit\_order\_column is set for UUID primary keys), LengthConstraintChecker (ensures DB length limits match Rails length validators), NullConstraintChecker (detects missing presence/inclusion/numericality validators on NOT NULL columns), EnumValueChecker (aligns DB enum values with Rails enums or inclusion validators), ThreeStateBooleanChecker (flags boolean columns missing NOT NULL constraints), and MissingIndexFindByChecker (uses Prism AST to detect find\_by calls on unindexed columns).
_lib/database\_consistency/checkers/column\checkers · high confidence
New database\_consistency CLI with install, autofix, and config options
The \bin/database\_consistency\ executable is introduced, replacing the previous \bin/console\ and \bin/setup\ scripts. This new CLI allows users to run an \install\ command to generate default configuration files, and provides options to specify additional config files (\-c\), generate TODO lists for failing checks (\-g\), and automatically fix issues (\-f\). It also supports scoping autofixes to specific checkers via \--only-checkers\. The tool requires being run from a Rails project root, loads the Rails environment (including Rails 6 Zeitwerk support), and executes database consistency checks.
bin · high confidence
New index consistency checkers for redundancy and uniqueness validation
The database consistency tool now includes four new checkers in the \index\_checkers\ module to enforce better database schema hygiene. \RedundantIndexChecker\ identifies non-unique B-tree indexes that are fully covered by another index on the same table with the same conditions, while \RedundantUniqueIndexChecker\ performs a similar check for unique indexes. Additionally, \UniqueIndexChecker\ ensures that unique database indexes are backed by corresponding \validates\_uniqueness\_of\ validators in the application code, flagging mismatches in columns or conditions. These changes help users detect and clean up unnecessary database indexes and ensure application-level validation aligns with database constraints.
_lib/database\_consistency/checkers/index\checkers · high confidence
New model consistency checkers for missing tables and view primary keys
This change introduces three new model checkers to enforce stricter database schema consistency. The new MissingTableChecker ensures that non-abstract models have a corresponding database table, reporting a failure if the table is absent. Additionally, the ViewPrimaryKeyChecker enforces that models backed by database views explicitly define a primary key that actually exists in the view's columns, preventing runtime errors in ActiveRecord 5+ applications. These checkers are built on a new base ModelChecker class that standardizes how model-based checks are processed.
_lib/database\_consistency/checkers/model\checkers · high confidence
New processor architecture for database consistency checks
The database consistency tool now uses a modular processor system to organize checks by domain (models, columns, associations, indexes, enums, and validators). Each processor iterates through its specific scope and runs all enabled checkers, providing a structured way to detect inconsistencies in Rails applications.
_lib/database\consistency/processors · high confidence
New validator checkers for uniqueness validation consistency
Added three new checker classes to validate database schema consistency against Rails uniqueness validators. The new \CaseSensitiveUniqueValidationChecker\ detects redundant \case\_sensitive: false\ options on PostgreSQL \citext\ columns, while \MissingUniqueIndexChecker\ ensures that uniqueness validators are backed by corresponding database unique indexes (including support for compound primary keys). These checkers are built on a new \ValidatorChecker\ base class that standardizes how validator metadata is processed.
_lib/database\_consistency/checkers/validator\checkers · high confidence
New validator-to-database consistency checkers for presence and numericality
Added two new consistency checkers to the \validators\_fraction\_checkers\ module: \ColumnPresenceChecker\ verifies that columns with \presence\ validators have corresponding \NOT NULL\ constraints in the database, including support for polymorphic associations and handling of weak options like \if\ or \on\; \NumericalityConstraintChecker\ ensures that \numericality\ validators with range options (e.g., \greater\_than\, \in\) have matching database \CHECK\ constraints, while correctly parsing SQL expressions to identify column names even when quoted or mixed with SQL keywords. Both checkers inherit from a new \ValidatorsFractionChecker\ base class and integrate with the existing reporting infrastructure to flag mismatches between Rails validators and database schema constraints.
_lib/database\_consistency/checkers/validators\_fraction\checkers · high confidence
Behavioural changes
Automatic checker registration via inheritance
Checkers are now automatically registered with the system when they inherit from the BaseChecker class, removing the need for manual registration steps. This simplifies the process of adding new consistency checks, as the framework detects and includes any new checker subclass automatically upon definition.
_lib/database\consistency/checkers · high confidence
Database Consistency v3.0.12: Major configuration, reporting, and debugging overhaul
This release introduces a comprehensive rewrite of the library's internal architecture, significantly changing how users configure, debug, and view database consistency checks. Configuration is now handled by a new \Configuration\ class that supports multiple YAML files, YAML aliases, and a \require\ directive to load custom checkers, with a new \LOG\_LEVEL\ setting for debug output. The reporting system has been refactored to use a structured \Report\ and \ReportBuilder\ instead of the previous \ComparisonResult\ module, and a new \DebugContext\ singleton provides structured debugging information. Error handling is improved via a \RescueError\ class that writes detailed stack traces and debug context to timestamped files. Additionally, a new \PrismHelper\ module leverages the Prism AST parser to index \find\_by\ calls for the \MissingIndexFindByChecker\, and \FilesHelper\ uses \Module.const\_source\_location\ to accurately identify project source files while excluding gems and the Ruby stdlib.
_lib/database\consistency · high confidence
Major architectural refactor introducing modular checkers, processors, and writers
The library has been restructured from a monolithic design into a modular architecture. The main entry point now instantiates a Configuration object and delegates analysis to a suite of dedicated Processors (for models, associations, columns, validators, indexes, and enums). Results are handled by a new Writer system, which replaces the previous comparison logic with specialized writers for simple reporting, TODO generation, and autofixing. This change introduces a comprehensive set of new checkers (e.g., for foreign key cascades, enum consistency, missing indexes, and view primary keys) and their corresponding autofix capabilities, significantly expanding the tool's detection and remediation scope.
lib · high confidence
Migrate CI to Appraisals and Docker, drop Travis CI
The project replaces the legacy Travis CI configuration with a new Appraisals setup that pins specific versions of ActiveRecord (4.2 through 8.1), database adapters, and Rubocop for each Ruby version (2.6–4.0). A Docker Compose file is added to provide a local PostgreSQL service for testing, and the Travis CI configuration file is removed.
(repo-wide) · high confidence
New association consistency checkers for foreign keys, indexes, and nullability
The association checking subsystem has been expanded with several new validators to enforce database schema integrity. A new base \AssociationChecker\ class centralizes logic for these checks. Specific new checkers include \ForeignKeyCascadeChecker\ to ensure foreign key cascade options match the Rails \dependent\ option, \ForeignKeyTypeChecker\ to verify that foreign key column types are large enough to cover the associated primary key, and \PolymorphicAssociationNullabilityChecker\ to ensure the foreign key and type columns in polymorphic associations share the same nullability constraint. Additionally, \MissingIndexChecker\ now distinguishes between standard and unique indexes for \has\_one\ associations, while \MissingDependentDestroyChecker\ and \MissingAssociationClassChecker\ provide stricter validation for dependent destroy setups and valid association class references respectively.
_lib/database\_consistency/checkers/association\checkers · high confidence
New writer subsystem for output, autofix, and TODO generation
The tool now uses a new \Writers\ module to handle report output and remediation. Users can generate a YAML TODO file via \TodoWriter\ to track issues, apply automatic fixes for supported database inconsistencies via \AutofixWriter\ (which maps error slugs to specific generator classes), or view simple console messages via \SimpleWriter\. This replaces the previous formatting logic with a structured, extensible writer architecture.
_lib/database\consistency/writers · high confidence
Refactor migration context handling in autofix helpers
The autofix helper module now determines the migration context by checking the arity of the ActiveRecord MigrationContext initializer and the availability of the schema migration object, ensuring compatibility across different ActiveRecord versions. This change replaces the previous approach of passing the migration context via a connection, aligning with the commit intent to use the migration connection pool's context directly.
_lib/database\consistency/writers/autofix/helpers · medium confidence
Test coverage
Added PostgreSQL-specific tests for EnumTypeChecker; Added test coverage for ForeignKeyTypeChecker on PostgreSQL and SQLite; Added test coverage for RedundantIndexChecker across MySQL, PostgreSQL, and SQLite; Added test coverage for autofix writer generators; Added test coverage for new and existing database consistency checkers; Added tests for BaseProcessor error handling; Added tests for PostgreSQL length constraint and unique index checkers; Added tests for RedundantUniqueIndexChecker across MySQL, PostgreSQL, and SQLite; Added tests for UniqueIndexChecker partial index support; Migrate test suite to multi-database support and add comprehensive configuration tests.
Dependencies
Add Rails 6, 7, and 8 example apps and update gem dependencies
This change introduces new example applications for Rails 6, 7, and 8, allowing users to see how the \database\_consistency\ gem integrates with modern Rails versions. The core gem's dependencies have been updated to support these versions, with \activerecord\ now required as a runtime dependency (\>= 3.2) and development dependencies for \mysql2\, \pg\, and \sqlite3\ added to facilitate testing across different database adapters. Additionally, the minimum supported Ruby version has been raised to 2.6.0, and a post-install message with funding information has been added to the gemspec.
(dependencies) · high confidence
Expanded ActiveRecord version support
The gemfile matrix has been extended to include support for ActiveRecord 8.0, 8.1, and the main development branch, alongside existing versions 4.2 through 7.2. This update ensures compatibility with the latest Rails releases and allows testing against the upcoming ActiveRecord 8 series.
gemfiles · 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 54.
Lenses
- Code Health 48
- Architecture 90
- Maturity 62
- Readiness 54
- Security 68
- Domain Modelling 100
- Accessibility 54
Changes since last survey
- 300 commits — 247 feature/other, 53 fixes
By area
- (root) — 151 commits
- lib/database_consistency — 103 commits
- spec/checkers — 15 commits
- .github/workflows — 8 commits
- (repo) — 7 commits
- .github/FUNDING.yml — 2 commits
- bin/database_consistency — 2 commits
- docs/wiki — 2 commits
- spec/fixtures — 2 commits
- .circleci/config.yml — 1 commit
- .github/copilot-instructions.md — 1 commit
- rails-example/.database_consistency.yml — 1 commit
- rails6-example/.database_consistency.yml — 1 commit
- rails7-example/app — 1 commit
- rails7-example/db — 1 commit
- rails8-example/app — 1 commit
- spec/writers — 1 commit
Notable commits
- fix: Few small fixes (#80)
- fix: Fix CI (#110)
- fix: Fix ColumnPresenceChecker autofix for polymorphic associations (#166)
- fix: Fix ColumnPresenceChecker to check associations (#96)
- fix: Fix EnumTypeChecker (#161)
- fix: Fix ForeignKeyCascadeChecker: handle missing primary key and support composite FK (#285)
- fix: Fix ForeignKeyChecker (#99)
- fix: Fix ForeignKeyTypeChecker (#112)
- fix: Fix ForeignKeyTypeChecker for custom private key (#75)
- fix: Fix ForeignKeyTypeChecker when associated class has no table (#206)
- fix: Fix HABTM support (#69)
- fix: Fix LengthConstraintChecker for PostgreSQL array feature (#62)
- fix: Fix MissingDependentDestroyChecker crash on polymorphic belongs_to associations (#284)
- fix: Fix MissingDependentDestroyChecker when classes are namespaced (#268)
- fix: Fix MissingIndexChecker (#120)
- fix: Fix MissingUniqueIndexChecker false positives with compound primary keys (#265)
- fix: Fix NumericalityConstraintChecker false positives on non-numerical validators (#310)
- fix: Fix ObjectSpace iteration crash when a class overrides .name to raise (#293)
- fix: Fix RedundantIndexChecker and RedundantUniqueIndexChecker (#85)
- fix: Fix UniqueIndexChecker to count associations (#141)
- …and 280 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
djezzzl/database_consistency 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 20 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 f5a696efbd3c30778efcfe98851968facda9e711 — 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-b51f968c9b10.