droppable_table 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rubocop.yml +58 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/CLAUDE.md +154 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +146 -0
- data/Rakefile +12 -0
- data/bin/console +11 -0
- data/bin/droppable_table +7 -0
- data/bin/setup +8 -0
- data/config/known_gems.yml +34 -0
- data/config/rails_internal_tables.yml +19 -0
- data/droppable_table.yml.sample +19 -0
- data/lib/droppable_table/analyzer.rb +230 -0
- data/lib/droppable_table/cli.rb +87 -0
- data/lib/droppable_table/config.rb +80 -0
- data/lib/droppable_table/model_collector.rb +131 -0
- data/lib/droppable_table/schema_parser.rb +57 -0
- data/lib/droppable_table/version.rb +5 -0
- data/lib/droppable_table.rb +15 -0
- data/sig/droppable_table.rbs +103 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ba364fbb050de85a819bf4271302bcf442dc59e79ade28e8f2055e70f7b58dd4
|
4
|
+
data.tar.gz: f4d90336ff5debca79df4ddf6d555feee2445d4b2681a15284f96af637b09132
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5fd213a9080bbca424289a6ca6c126388eef4c2fd6909938d09da2a58272d5705fd1a58fb32f4ad62a74c097204dd7a21d515b3508bb342d71d2ba0aae45db6
|
7
|
+
data.tar.gz: 207ec1f2d311c6aa9a5cc294a94ee32a0726433bd326d62459e0a74c6b74d77e134ae8df14c2e41325a810ad15fcef511254ee19eaea9932c4dbea5242f9cb37
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.0
|
3
|
+
NewCops: enable
|
4
|
+
Exclude:
|
5
|
+
- 'vendor/**/*'
|
6
|
+
- 'test/fixtures/**/*'
|
7
|
+
|
8
|
+
Style/StringLiterals:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Style/StringLiteralsInInterpolation:
|
13
|
+
Enabled: true
|
14
|
+
EnforcedStyle: double_quotes
|
15
|
+
|
16
|
+
Layout/LineLength:
|
17
|
+
Max: 120
|
18
|
+
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 30
|
21
|
+
Exclude:
|
22
|
+
- 'test/**/*'
|
23
|
+
|
24
|
+
Metrics/AbcSize:
|
25
|
+
Max: 40
|
26
|
+
Exclude:
|
27
|
+
- 'test/**/*'
|
28
|
+
|
29
|
+
Metrics/ClassLength:
|
30
|
+
Max: 200
|
31
|
+
|
32
|
+
Metrics/CyclomaticComplexity:
|
33
|
+
Max: 10
|
34
|
+
Exclude:
|
35
|
+
- 'test/**/*'
|
36
|
+
|
37
|
+
Metrics/BlockLength:
|
38
|
+
Exclude:
|
39
|
+
- 'test/**/*'
|
40
|
+
- 'spec/**/*'
|
41
|
+
- '*.gemspec'
|
42
|
+
|
43
|
+
Style/Documentation:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/FrozenStringLiteralComment:
|
47
|
+
Enabled: true
|
48
|
+
|
49
|
+
# Allow both styles for arrays
|
50
|
+
Style/WordArray:
|
51
|
+
Enabled: false
|
52
|
+
|
53
|
+
Style/SymbolArray:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
# Disable development dependencies warning (they're fine in gemspec)
|
57
|
+
Gemspec/DevelopmentDependencies:
|
58
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.6
|
data/CHANGELOG.md
ADDED
data/CLAUDE.md
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
# CLAUDE.md
|
2
|
+
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
DroppableTable is a Ruby gem that analyzes Rails applications to identify potentially droppable database tables - tables that exist in the schema but have no corresponding ActiveRecord models. This helps with database cleanup and maintenance.
|
8
|
+
|
9
|
+
## Commands
|
10
|
+
|
11
|
+
### Development Setup
|
12
|
+
```bash
|
13
|
+
# Install dependencies
|
14
|
+
bundle install
|
15
|
+
|
16
|
+
# Run all tests
|
17
|
+
bundle exec rake test
|
18
|
+
|
19
|
+
# Run a specific test file
|
20
|
+
bundle exec ruby -Ilib:test test/test_analyzer.rb
|
21
|
+
|
22
|
+
# Run tests from dummy app directory (required for some tests)
|
23
|
+
cd test/fixtures/dummy_app && RAILS_ENV=test bundle exec ruby -I../../../lib:../../.. ../../../test/test_analyzer.rb
|
24
|
+
|
25
|
+
# Run linter
|
26
|
+
bundle exec rubocop
|
27
|
+
|
28
|
+
# Run linter with auto-correction
|
29
|
+
bundle exec rubocop -A
|
30
|
+
|
31
|
+
# Build the gem
|
32
|
+
gem build droppable_table.gemspec
|
33
|
+
|
34
|
+
# Install gem locally
|
35
|
+
gem install ./droppable_table-0.1.0.gem
|
36
|
+
```
|
37
|
+
|
38
|
+
### Release Process
|
39
|
+
```bash
|
40
|
+
# Ensure all tests pass
|
41
|
+
bundle exec rake test
|
42
|
+
|
43
|
+
# Check RuboCop
|
44
|
+
bundle exec rubocop
|
45
|
+
|
46
|
+
# Build and test locally
|
47
|
+
gem build droppable_table.gemspec
|
48
|
+
gem install ./droppable_table-*.gem
|
49
|
+
|
50
|
+
# Release to RubyGems (requires credentials)
|
51
|
+
bundle exec rake release
|
52
|
+
```
|
53
|
+
|
54
|
+
### Testing the Gem
|
55
|
+
```bash
|
56
|
+
# From a Rails application directory
|
57
|
+
bundle exec droppable_table analyze
|
58
|
+
bundle exec droppable_table analyze --json
|
59
|
+
bundle exec droppable_table analyze --strict
|
60
|
+
bundle exec droppable_table version
|
61
|
+
|
62
|
+
# Test with GitHub source
|
63
|
+
# In target app's Gemfile: gem 'droppable_table', github: 'konpyu/droppable_table'
|
64
|
+
```
|
65
|
+
|
66
|
+
## Architecture
|
67
|
+
|
68
|
+
### Core Components
|
69
|
+
|
70
|
+
1. **Analyzer** (`lib/droppable_table/analyzer.rb`)
|
71
|
+
- Central orchestrator that coordinates the analysis process
|
72
|
+
- Workflow: check migrations → detect schema format → collect schema tables → load models → identify droppable tables
|
73
|
+
- Handles both text and JSON report generation
|
74
|
+
- Manages multi-database support (primary, secondary databases)
|
75
|
+
|
76
|
+
2. **SchemaParser** (`lib/droppable_table/schema_parser.rb`)
|
77
|
+
- Parses Rails schema files (`schema.rb` or `structure.sql`)
|
78
|
+
- Currently implements Ruby schema parsing, SQL parsing is TODO
|
79
|
+
- Returns array of table information
|
80
|
+
|
81
|
+
3. **ModelCollector** (`lib/droppable_table/model_collector.rb`)
|
82
|
+
- Loads Rails environment and collects all ActiveRecord models
|
83
|
+
- Detects STI (Single Table Inheritance) base tables
|
84
|
+
- Identifies HABTM (has_and_belongs_to_many) join tables
|
85
|
+
- Handles custom table names and multi-database models
|
86
|
+
|
87
|
+
4. **Config** (`lib/droppable_table/config.rb`)
|
88
|
+
- Loads configuration from YAML files
|
89
|
+
- Manages exclusion lists (Rails internal tables, gem tables, user-defined)
|
90
|
+
- Handles strict mode settings for CI integration
|
91
|
+
- Default configs in `config/rails_internal_tables.yml` and `config/known_gems.yml`
|
92
|
+
|
93
|
+
5. **CLI** (`lib/droppable_table/cli.rb`)
|
94
|
+
- Thor-based command line interface
|
95
|
+
- Commands: `analyze` (default), `version`
|
96
|
+
- Handles output formatting, strict mode, and error reporting
|
97
|
+
|
98
|
+
### Key Design Decisions
|
99
|
+
|
100
|
+
- **Multi-database Support**: Detects and analyzes multiple schema files (e.g., `schema.rb`, `secondary_schema.rb`)
|
101
|
+
- **Exclusion System**: Three-tier exclusion (Rails internal, known gems, user-defined)
|
102
|
+
- **STI Awareness**: STI base tables are not considered droppable even if no direct model exists
|
103
|
+
- **HABTM Recognition**: Join tables are recognized and not marked as droppable
|
104
|
+
- **Test Environment**: Migration checks are skipped in test environment to avoid false positives
|
105
|
+
|
106
|
+
### Testing Infrastructure
|
107
|
+
|
108
|
+
The gem includes a full Rails dummy application in `test/fixtures/dummy_app/` with:
|
109
|
+
- Multiple databases (primary and secondary)
|
110
|
+
- STI models (Vehicle → Car)
|
111
|
+
- HABTM relationships (User ↔ Role)
|
112
|
+
- Custom table names (CustomTableModel)
|
113
|
+
- Orphaned tables for testing (abandoned_logs, legacy_data)
|
114
|
+
|
115
|
+
### Configuration
|
116
|
+
|
117
|
+
Users can create `droppable_table.yml` to:
|
118
|
+
- Exclude specific tables
|
119
|
+
- Exclude tables from specific gems
|
120
|
+
- Enable strict mode for CI (fails if new droppable tables are found)
|
121
|
+
|
122
|
+
Sample configuration:
|
123
|
+
```yaml
|
124
|
+
excluded_tables:
|
125
|
+
- legacy_payments
|
126
|
+
- archived_data
|
127
|
+
|
128
|
+
excluded_gems:
|
129
|
+
- papertrail
|
130
|
+
- delayed_job
|
131
|
+
|
132
|
+
strict_mode:
|
133
|
+
enabled: true
|
134
|
+
baseline_file: .droppable_table_baseline.json
|
135
|
+
```
|
136
|
+
|
137
|
+
### RuboCop Configuration
|
138
|
+
|
139
|
+
The project enforces Ruby style guidelines with some customizations:
|
140
|
+
- String style: double quotes
|
141
|
+
- Line length: 120 characters
|
142
|
+
- Method length: 30 lines (relaxed for complex analysis methods)
|
143
|
+
- Test files excluded from some metrics
|
144
|
+
|
145
|
+
## Important Implementation Notes
|
146
|
+
|
147
|
+
### Migration Status Checking
|
148
|
+
The migration check in `Analyzer#check_migration_status` is skipped in test environment and handles different Rails versions gracefully by trying multiple approaches.
|
149
|
+
|
150
|
+
### Executable Setup
|
151
|
+
The gem's executable is configured in `gemspec` with `spec.executables = ["droppable_table"]` and must be included when building the gem.
|
152
|
+
|
153
|
+
### Test Execution Context
|
154
|
+
Some tests (particularly `test_model_collector.rb` and `test_analyzer.rb`) must be run from within the dummy app directory to properly load the Rails environment.
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 konpyu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# DroppableTable
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/droppable_table)
|
4
|
+
[](https://github.com/konpyu/droppable_table/actions/workflows/main.yml)
|
5
|
+
|
6
|
+
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.
|
7
|
+
|
8
|
+
## Features
|
9
|
+
|
10
|
+
- 🔍 Detects tables without corresponding ActiveRecord models
|
11
|
+
- 🚀 Supports multiple databases (primary, secondary, etc.)
|
12
|
+
- 🎯 Recognizes STI (Single Table Inheritance) tables
|
13
|
+
- 🔗 Identifies HABTM (has_and_belongs_to_many) join tables
|
14
|
+
- ⚙️ Configurable exclusion lists for tables and gems
|
15
|
+
- 📊 Multiple output formats (text and JSON)
|
16
|
+
- 🔒 Strict mode for CI integration
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
group :development, :test do
|
24
|
+
gem 'droppable_table'
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
And then execute:
|
29
|
+
|
30
|
+
$ bundle install
|
31
|
+
|
32
|
+
Or install it yourself as:
|
33
|
+
|
34
|
+
$ gem install droppable_table
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
### Basic Usage
|
39
|
+
|
40
|
+
From your Rails application root directory:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
# Analyze and show results (default command)
|
44
|
+
bundle exec droppable_table
|
45
|
+
|
46
|
+
# Same as above - analyze is the default command
|
47
|
+
bundle exec droppable_table analyze
|
48
|
+
|
49
|
+
# Output in JSON format
|
50
|
+
bundle exec droppable_table analyze --json
|
51
|
+
|
52
|
+
# Use custom configuration file
|
53
|
+
bundle exec droppable_table analyze --config custom_config.yml
|
54
|
+
|
55
|
+
# Show version
|
56
|
+
bundle exec droppable_table version
|
57
|
+
```
|
58
|
+
|
59
|
+
### Configuration
|
60
|
+
|
61
|
+
Create a `droppable_table.yml` file in your Rails root:
|
62
|
+
|
63
|
+
```yaml
|
64
|
+
# Tables to exclude from the droppable list
|
65
|
+
excluded_tables:
|
66
|
+
- legacy_payments # Keep for audit trail
|
67
|
+
- archived_data # Historical data
|
68
|
+
- temp_migration # Temporary migration table
|
69
|
+
|
70
|
+
# Exclude tables from specific gems
|
71
|
+
excluded_gems:
|
72
|
+
- papertrail # Exclude papertrail's versions table
|
73
|
+
- delayed_job # Exclude delayed_jobs table
|
74
|
+
|
75
|
+
# Strict mode for CI
|
76
|
+
strict_mode:
|
77
|
+
enabled: true
|
78
|
+
baseline_file: .droppable_table_baseline.json
|
79
|
+
```
|
80
|
+
|
81
|
+
### Strict Mode (CI Integration)
|
82
|
+
|
83
|
+
Strict mode helps prevent accidental table additions:
|
84
|
+
|
85
|
+
```bash
|
86
|
+
# First run creates a baseline
|
87
|
+
bundle exec droppable_table analyze --strict
|
88
|
+
|
89
|
+
# Subsequent runs will fail if new droppable tables are found
|
90
|
+
bundle exec droppable_table analyze --strict
|
91
|
+
```
|
92
|
+
|
93
|
+
### Example Output
|
94
|
+
|
95
|
+
```
|
96
|
+
DroppableTable Analysis Report
|
97
|
+
========================================
|
98
|
+
|
99
|
+
Summary:
|
100
|
+
Total tables in schema: 25
|
101
|
+
Tables with models: 20
|
102
|
+
STI base tables: 2
|
103
|
+
HABTM join tables: 3
|
104
|
+
Excluded tables: 15
|
105
|
+
Potentially droppable: 2
|
106
|
+
|
107
|
+
Potentially droppable tables:
|
108
|
+
- abandoned_logs
|
109
|
+
- legacy_sessions
|
110
|
+
```
|
111
|
+
|
112
|
+
## How It Works
|
113
|
+
|
114
|
+
1. **Schema Analysis**: Parses your `db/schema.rb` (or `structure.sql`) to find all tables
|
115
|
+
2. **Model Detection**: Loads all ActiveRecord models in your application
|
116
|
+
3. **Relationship Analysis**:
|
117
|
+
- Identifies STI base tables (won't be marked as droppable)
|
118
|
+
- Detects HABTM join tables (won't be marked as droppable)
|
119
|
+
4. **Exclusion Processing**: Applies exclusion rules from configuration
|
120
|
+
5. **Report Generation**: Shows tables that exist in schema but have no models
|
121
|
+
|
122
|
+
## Built-in Exclusions
|
123
|
+
|
124
|
+
The gem automatically excludes:
|
125
|
+
- Rails internal tables (schema_migrations, ar_internal_metadata, etc.)
|
126
|
+
- Active Storage tables
|
127
|
+
- Action Text tables
|
128
|
+
- Common gem tables (when gems are listed in excluded_gems)
|
129
|
+
|
130
|
+
## Development
|
131
|
+
|
132
|
+
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.
|
133
|
+
|
134
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
135
|
+
|
136
|
+
## Contributing
|
137
|
+
|
138
|
+
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](https://github.com/konpyu/droppable_table/blob/main/CODE_OF_CONDUCT.md).
|
139
|
+
|
140
|
+
## License
|
141
|
+
|
142
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
143
|
+
|
144
|
+
## Code of Conduct
|
145
|
+
|
146
|
+
Everyone interacting in the DroppableTable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/konpyu/droppable_table/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "droppable_table"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require "irb"
|
11
|
+
IRB.start(__FILE__)
|
data/bin/droppable_table
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Tables created by popular gems
|
2
|
+
papertrail:
|
3
|
+
- versions
|
4
|
+
- version_associations
|
5
|
+
|
6
|
+
delayed_job:
|
7
|
+
- delayed_jobs
|
8
|
+
|
9
|
+
devise:
|
10
|
+
- users # Note: This might be customized
|
11
|
+
|
12
|
+
friendly_id:
|
13
|
+
- friendly_id_slugs
|
14
|
+
|
15
|
+
acts_as_taggable:
|
16
|
+
- tags
|
17
|
+
- taggings
|
18
|
+
|
19
|
+
impressionist:
|
20
|
+
- impressions
|
21
|
+
|
22
|
+
audited:
|
23
|
+
- audits
|
24
|
+
|
25
|
+
ahoy:
|
26
|
+
- ahoy_visits
|
27
|
+
- ahoy_events
|
28
|
+
|
29
|
+
blazer:
|
30
|
+
- blazer_queries
|
31
|
+
- blazer_audits
|
32
|
+
- blazer_dashboards
|
33
|
+
- blazer_dashboard_queries
|
34
|
+
- blazer_checks
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Rails internal tables that should always be excluded
|
2
|
+
- schema_migrations
|
3
|
+
- ar_internal_metadata
|
4
|
+
- active_storage_blobs
|
5
|
+
- active_storage_attachments
|
6
|
+
- active_storage_variant_records
|
7
|
+
- action_text_rich_texts
|
8
|
+
- action_mailbox_inbound_emails
|
9
|
+
- action_mailbox_entries
|
10
|
+
- solid_queue_blocked_executions
|
11
|
+
- solid_queue_claimed_executions
|
12
|
+
- solid_queue_failed_executions
|
13
|
+
- solid_queue_jobs
|
14
|
+
- solid_queue_pauses
|
15
|
+
- solid_queue_processes
|
16
|
+
- solid_queue_ready_executions
|
17
|
+
- solid_queue_recurring_executions
|
18
|
+
- solid_queue_scheduled_executions
|
19
|
+
- solid_queue_semaphores
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Example configuration file for droppable_table gem
|
2
|
+
# Copy this file to droppable_table.yml and customize as needed
|
3
|
+
|
4
|
+
# Tables to exclude from the droppable list (user defined)
|
5
|
+
excluded_tables:
|
6
|
+
- countries
|
7
|
+
- languages
|
8
|
+
- static_data
|
9
|
+
|
10
|
+
# Gems to exclude (in addition to the default list)
|
11
|
+
excluded_gems:
|
12
|
+
- papertrail
|
13
|
+
- delayed_job
|
14
|
+
- custom_gem
|
15
|
+
|
16
|
+
# Strict mode settings for CI integration
|
17
|
+
strict_mode:
|
18
|
+
enabled: false
|
19
|
+
baseline_file: .droppable_table_baseline.json
|