schema_reaper 1.0.14 → 1.0.15
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 +4 -4
- data/CHANGELOG.md +44 -0
- data/lib/schema_reaper/static/scanner.rb +37 -25
- data/lib/schema_reaper/version.rb +1 -1
- data/schema_reaper.gemspec +11 -9
- metadata +15 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6b327fade324c6f2e9a871da57ae46814c1b077a1aca3aec64ca6681f270ffe6
|
|
4
|
+
data.tar.gz: d63156d86d7dc44e92204475c3d23ffa7e6b87730d0a436dc9aefd041ea8b843
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cb3fe82c18f9f198ec544089305b183f2a413123093edd6f437a04c8d0b32879c123d1e4d1c338a1e03539a8eb16847406bb21f4eab5932ed6b4aba4fcdf461e
|
|
7
|
+
data.tar.gz: 1c1cf99e43ff66383f5b3bb0c42d5cfec209cbc8dab3bb986e734b6dcf75706c5ed1ecbf09d61f116ce2883957630f0ceeff7a102fb49793fe73cd93cd8283ad
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.15] - 2026-09-18
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- **`dead_column` still missed the two gems its own macro-detection feature
|
|
7
|
+
named as motivation.** 1.0.14 added recognition for `has_secure_password`,
|
|
8
|
+
`attr_encrypted`, and Lockbox macro columns, but only the first actually
|
|
9
|
+
worked. `attr_encrypted`'s real default column naming is a *prefix*
|
|
10
|
+
(`encrypted_<attr>`), confirmed against the gem's own
|
|
11
|
+
`attr_encrypted_default_options`; the feature generated a suffix guess
|
|
12
|
+
that never matched it. Lockbox's real macro is `has_encrypted`; the
|
|
13
|
+
feature checked for `lockbox_encrypts`, which is not a method that
|
|
14
|
+
exists in the gem, so it never even fired for genuine Lockbox code.
|
|
15
|
+
Rewritten as a macro-name -> column-template table so each macro's real
|
|
16
|
+
naming shape is expressed explicitly, and dropped an unnecessary
|
|
17
|
+
suffix guess for Rails' native `encrypts` (which stores ciphertext in
|
|
18
|
+
the original column and creates no extra one). Eight new specs cover
|
|
19
|
+
all four macros -- this had no test coverage before. (#15, mitkush)
|
|
20
|
+
|
|
21
|
+
## [1.0.14] - 2026-09-18
|
|
22
|
+
|
|
23
|
+
Published directly without a version-bump commit or tag; this entry
|
|
24
|
+
reconciles the record after the fact. Confirmed by diffing the
|
|
25
|
+
published gem against `main` at the time -- the only difference was the
|
|
26
|
+
version string.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
- `duplicate_index` respecting uniqueness and partial `WHERE` clauses --
|
|
30
|
+
see 1.0.13's entry for the underlying issue; this release adds the fix.
|
|
31
|
+
(#12, mitkush)
|
|
32
|
+
- `dead_column` missing `has_secure_password`, `encrypts`, and
|
|
33
|
+
`attr_encrypted` macro columns -- a virtual attribute like
|
|
34
|
+
`has_secure_password` never has its generated column name
|
|
35
|
+
(`password_digest`) written anywhere in application code, so it looked
|
|
36
|
+
unreferenced. (aksshatt)
|
|
37
|
+
|
|
38
|
+
### Known issue
|
|
39
|
+
- The `attr_encrypted`/Lockbox part of the macro-column fix above does
|
|
40
|
+
not work as intended: it derives a suffix-based column name
|
|
41
|
+
(`<attr>_encrypted`) that does not match `attr_encrypted`'s actual
|
|
42
|
+
default naming (`encrypted_<attr>`, a prefix), and it references a
|
|
43
|
+
`lockbox_encrypts` macro name that does not exist in Lockbox -- the
|
|
44
|
+
gem's real method is `has_encrypted`. `has_secure_password` and Rails'
|
|
45
|
+
native `encrypts` are unaffected and work correctly. Tracked for 1.0.15.
|
|
46
|
+
|
|
3
47
|
## [1.0.13] - 2026-09-18
|
|
4
48
|
|
|
5
49
|
### Fixed
|
|
@@ -12,15 +12,37 @@ module SchemaReaper
|
|
|
12
12
|
RUBY_GLOB = "**/*.rb"
|
|
13
13
|
WORD_RE = /[a-z_][a-z0-9_]*/i.freeze
|
|
14
14
|
|
|
15
|
-
# Macros
|
|
16
|
-
#
|
|
17
|
-
# code
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
# Macros whose generated column name differs from the virtual attribute
|
|
16
|
+
# declared in the call, so the real column name never appears anywhere
|
|
17
|
+
# in application code and would otherwise look dead. %s is replaced with
|
|
18
|
+
# the declared attribute.
|
|
19
|
+
#
|
|
20
|
+
# Several shapes are listed for some macros on purpose: getting the real
|
|
21
|
+
# default right matters most, but an extra guess that never matches a
|
|
22
|
+
# real column is harmless -- over-collecting is this scanner's stated
|
|
23
|
+
# design, and both attr_encrypted and Lockbox let a call override their
|
|
24
|
+
# naming, which a static scan cannot always evaluate.
|
|
25
|
+
#
|
|
26
|
+
# attr_encrypted's own default is a PREFIX (encrypted_<attr>), not a
|
|
27
|
+
# suffix -- confirmed against the gem's own attr_encrypted_default_options
|
|
28
|
+
# (prefix: "encrypted_", suffix: ""). The suffix form is kept as a
|
|
29
|
+
# fallback for calls that override it.
|
|
30
|
+
#
|
|
31
|
+
# Lockbox's real macro is has_encrypted, not lockbox_encrypts.
|
|
32
|
+
#
|
|
33
|
+
# Rails' own `encrypts` has no entry: it stores ciphertext in the
|
|
34
|
+
# original column, so the bare attribute name is what needs to be
|
|
35
|
+
# "used", and that is already picked up as a symbol literal by
|
|
36
|
+
# tokens_for below -- do not add a suffix pattern for it.
|
|
37
|
+
MACRO_COLUMN_TEMPLATES = {
|
|
38
|
+
"has_secure_password" => ["%s_digest"],
|
|
39
|
+
"attr_encrypted" => ["encrypted_%s", "%s_encrypted", "%s_ciphertext"],
|
|
40
|
+
"has_encrypted" => ["%s_ciphertext", "%s_iv", "%s_tag"]
|
|
41
|
+
}.freeze
|
|
42
|
+
|
|
43
|
+
# The attribute a macro implies when called with no explicit name, e.g.
|
|
44
|
+
# bare `has_secure_password` -> :password.
|
|
45
|
+
MACRO_DEFAULT_ATTR = { "has_secure_password" => "password" }.freeze
|
|
24
46
|
|
|
25
47
|
# Node classes whose #name (or #unescaped) is a bare identifier we treat
|
|
26
48
|
# as a possible column/table reference.
|
|
@@ -89,24 +111,14 @@ module SchemaReaper
|
|
|
89
111
|
end
|
|
90
112
|
end
|
|
91
113
|
|
|
92
|
-
# `has_secure_password` / `encrypts :field` / `attr_encrypted :field`
|
|
93
|
-
# never write their generated column name (password_digest,
|
|
94
|
-
# field_ciphertext, ...) anywhere in source -- only the virtual
|
|
95
|
-
# attribute name. Derive the column names a macro call implies so they
|
|
96
|
-
# count as "used" instead of looking dead.
|
|
97
114
|
def macro_derived_tokens(node)
|
|
98
115
|
call_name = node.name&.to_s
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
elsif ENCRYPTED_MACROS.include?(call_name)
|
|
106
|
-
macro_symbol_args(node).flat_map { |a| ENCRYPTED_SUFFIXES.map { |s| "#{a}#{s}" } }
|
|
107
|
-
else
|
|
108
|
-
[]
|
|
109
|
-
end
|
|
116
|
+
templates = call_name && MACRO_COLUMN_TEMPLATES[call_name]
|
|
117
|
+
return [] unless templates
|
|
118
|
+
|
|
119
|
+
attrs = macro_symbol_args(node)
|
|
120
|
+
attrs = [MACRO_DEFAULT_ATTR[call_name]].compact if attrs.empty?
|
|
121
|
+
attrs.product(templates).map { |attr, template| format(template, attr) }
|
|
110
122
|
end
|
|
111
123
|
|
|
112
124
|
# Leading bare symbol arguments of a call, e.g. `encrypts :a, :b, purpose: :x`
|
data/schema_reaper.gemspec
CHANGED
|
@@ -9,15 +9,17 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.email = ["akshatpegwar5@gmail.com", "mitanshukushwah@gmail.com"]
|
|
10
10
|
|
|
11
11
|
spec.summary = "Find and safely remove schema dead-weight in Rails + PostgreSQL apps."
|
|
12
|
-
spec.description =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
spec.description = <<~DESC.strip
|
|
13
|
+
schema_reaper scans a Rails + PostgreSQL app for schema debt that's easy to accumulate and hard to find by hand.
|
|
14
|
+
|
|
15
|
+
It checks your live database against your codebase and flags three kinds of problems: things nothing references anymore (dead columns and dead tables), index trouble (indexes nobody queries, indexes made redundant by a wider index that already covers them, and foreign-key columns with no index at all), and degenerate data (columns that are always NULL, or hold the exact same value in every row).
|
|
16
|
+
|
|
17
|
+
Every finding comes with a confidence score, an estimate of the disk space removing it would reclaim, and a concrete fix. For a column, that's a two-step migration: stop reading it first, then drop it once you've confirmed nothing broke. An optional runtime tracker can sample real production traffic to raise confidence further, for cases a static code scan alone can't settle.
|
|
18
|
+
|
|
19
|
+
Reports come as a colored terminal summary, JSON, Markdown for a PR comment, or SARIF for GitHub code scanning -- plus a CI baseline gate and a trend log to track progress release over release.
|
|
20
|
+
|
|
21
|
+
PostgreSQL only for now. Requires Ruby 2.7 or later. Full usage is in the README.
|
|
22
|
+
DESC
|
|
21
23
|
spec.homepage = "https://github.com/aksshatt/schema_reaper"
|
|
22
24
|
spec.license = "MIT"
|
|
23
25
|
spec.required_ruby_version = ">= 2.7.0"
|
metadata
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: schema_reaper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- aksshatt
|
|
8
8
|
- mitkush
|
|
9
|
-
autorequire:
|
|
9
|
+
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
12
|
date: 2026-09-18 00:00:00.000000000 Z
|
|
@@ -79,14 +79,16 @@ dependencies:
|
|
|
79
79
|
- - "~>"
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
81
|
version: '1.5'
|
|
82
|
-
description:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
estimate, and
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
description: |-
|
|
83
|
+
schema_reaper scans a Rails + PostgreSQL app for schema debt that's easy to accumulate and hard to find by hand.
|
|
84
|
+
|
|
85
|
+
It checks your live database against your codebase and flags three kinds of problems: things nothing references anymore (dead columns and dead tables), index trouble (indexes nobody queries, indexes made redundant by a wider index that already covers them, and foreign-key columns with no index at all), and degenerate data (columns that are always NULL, or hold the exact same value in every row).
|
|
86
|
+
|
|
87
|
+
Every finding comes with a confidence score, an estimate of the disk space removing it would reclaim, and a concrete fix. For a column, that's a two-step migration: stop reading it first, then drop it once you've confirmed nothing broke. An optional runtime tracker can sample real production traffic to raise confidence further, for cases a static code scan alone can't settle.
|
|
88
|
+
|
|
89
|
+
Reports come as a colored terminal summary, JSON, Markdown for a PR comment, or SARIF for GitHub code scanning -- plus a CI baseline gate and a trend log to track progress release over release.
|
|
90
|
+
|
|
91
|
+
PostgreSQL only for now. Requires Ruby 2.7 or later. Full usage is in the README.
|
|
90
92
|
email:
|
|
91
93
|
- akshatpegwar5@gmail.com
|
|
92
94
|
- mitanshukushwah@gmail.com
|
|
@@ -157,7 +159,7 @@ metadata:
|
|
|
157
159
|
wiki_uri: https://github.com/aksshatt/schema_reaper/wiki
|
|
158
160
|
funding_uri: https://github.com/sponsors/aksshatt
|
|
159
161
|
rubygems_mfa_required: 'true'
|
|
160
|
-
post_install_message:
|
|
162
|
+
post_install_message:
|
|
161
163
|
rdoc_options: []
|
|
162
164
|
require_paths:
|
|
163
165
|
- lib
|
|
@@ -172,8 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
172
174
|
- !ruby/object:Gem::Version
|
|
173
175
|
version: '0'
|
|
174
176
|
requirements: []
|
|
175
|
-
rubygems_version: 3.
|
|
176
|
-
signing_key:
|
|
177
|
+
rubygems_version: 3.3.3
|
|
178
|
+
signing_key:
|
|
177
179
|
specification_version: 4
|
|
178
180
|
summary: Find and safely remove schema dead-weight in Rails + PostgreSQL apps.
|
|
179
181
|
test_files: []
|