Class: RuboCop::Cop::DevDoc::Migration::AvoidJsonColumn
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::DevDoc::Migration::AvoidJsonColumn
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/dev_doc/migration/avoid_json_column.rb
Overview
Prefer ‘jsonb` over `json` for column types.
## Rationale ‘jsonb` stores data in a binary format that supports indexing, querying with operators (`->`, `->>`, `@>`), and is generally faster to read. Use `json` only if you need to preserve key order or exact formatting of the original JSON string — which is rare in practice.
❌
t.json :metadata
✔️
t.jsonb :metadata
Constant Summary collapse
- MSG =
'Use `jsonb` instead of `json`. `jsonb` supports indexing and is faster to read.'.freeze
- RESTRICT_ON_SEND =
%i[json].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
31 32 33 34 35 |
# File 'lib/rubocop/cop/dev_doc/migration/avoid_json_column.rb', line 31 def on_send(node) add_offense(node.loc.selector) do |corrector| corrector.replace(node.loc.selector, 'jsonb') end end |