0.0
The project is in a healthy, maintained state
Analyzes Rails schema files and ActiveRecord models to identify tables that exist in schema but have no corresponding models, helping with database cleanup.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 5.0
>= 6.0
>= 1.4

Runtime

>= 6.0
~> 1.0
 Project Readme

DroppableTable

Gem Version Ruby

A Ruby gem that helps identify potentially droppable tables in Rails applications by analyzing schema files and ActiveRecord models. It finds tables that exist in your database schema but have no corresponding models, helping with database cleanup and maintenance.

Features

  • 🔍 Detects tables without corresponding ActiveRecord models
  • 🚀 Supports multiple databases (primary, secondary, etc.)
  • 🎯 Recognizes STI (Single Table Inheritance) tables
  • 🔗 Identifies HABTM (has_and_belongs_to_many) join tables
  • ⚙️ Configurable exclusion lists for tables and gems
  • 📊 Multiple output formats (text and JSON)
  • 🔒 Strict mode for CI integration

Installation

Add this line to your application's Gemfile:

group :development, :test do
  gem 'droppable_table'
end

And then execute:

$ bundle install

Or install it yourself as:

$ gem install droppable_table

Usage

Basic Usage

From your Rails application root directory:

# Analyze and show results (default command)
bundle exec droppable_table

# Same as above - analyze is the default command
bundle exec droppable_table analyze

# Output in JSON format
bundle exec droppable_table analyze --json

# Use custom configuration file
bundle exec droppable_table analyze --config custom_config.yml

# Show version
bundle exec droppable_table version

Configuration

Create a droppable_table.yml file in your Rails root:

# Tables to exclude from the droppable list
excluded_tables:
  - legacy_payments    # Keep for audit trail
  - archived_data      # Historical data
  - temp_migration     # Temporary migration table

# Exclude tables from specific gems
excluded_gems:
  - papertrail         # Exclude papertrail's versions table
  - delayed_job        # Exclude delayed_jobs table

# Strict mode for CI
strict_mode:
  enabled: true
  baseline_file: .droppable_table_baseline.json

Strict Mode (CI Integration)

Strict mode helps prevent accidental table additions:

# First run creates a baseline
bundle exec droppable_table analyze --strict

# Subsequent runs will fail if new droppable tables are found
bundle exec droppable_table analyze --strict

Example Output

DroppableTable Analysis Report
========================================

Summary:
  Total tables in schema: 25
  Tables with models: 20
  STI base tables: 2
  HABTM join tables: 3
  Excluded tables: 15
  Potentially droppable: 2

Potentially droppable tables:
  - abandoned_logs
  - legacy_sessions

How It Works

  1. Schema Analysis: Parses your db/schema.rb (or structure.sql) to find all tables
  2. Model Detection: Loads all ActiveRecord models in your application
  3. Relationship Analysis:
    • Identifies STI base tables (won't be marked as droppable)
    • Detects HABTM join tables (won't be marked as droppable)
  4. Exclusion Processing: Applies exclusion rules from configuration
  5. Report Generation: Shows tables that exist in schema but have no models

Built-in Exclusions

The gem automatically excludes:

  • Rails internal tables (schema_migrations, ar_internal_metadata, etc.)
  • Active Storage tables
  • Action Text tables
  • Common gem tables (when gems are listed in excluded_gems)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/konpyu/droppable_table. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the DroppableTable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.