Junior Track Roadmap

ActiveRecord: store/JSONB

ActiveRecord: store/JSONB looks at how one Rails app uses Postgres jsonb columns. It starts with the migration that converted bilingual string columns to jsonb with jsonb_build_object, and the down method that reverses it. It tries store_accessor on a disposable table and explains why the app wrote its own Translatable concern. It then queries jsonb in SQL with ->> and COALESCE, examines what GIN and trigram indexes speed up, and shows jsonb holding OAuth payloads and arrays of hints.

What you'll learn

  • ✓Converting string columns to jsonb in a reversible migration with jsonb_build_object and ->>
  • ✓How store_accessor works on a jsonb column, and why symbol keys return nil after a reload
  • ✓Why a hand-written Translatable concern handles the pt-BR locale and repeated keys, and its dirty tracking cost
  • ✓Querying jsonb in SQL with ->>, -> and COALESCE for a locale fallback
  • ✓Which operators a default GIN index accelerates, and when pg_trgm expression indexes fit
  • ✓Using jsonb for data whose shape varies, such as OAuth payloads and arrays of hashes
Free preview · Lesson 1 3 min read

The migration that turned the bilingual columns into JSONB

Catalog::Course#title and #description, Catalog::Lesson#title and #content_markdown, Catalog::Challenge#instruction, #solution and #hints: every one of these columns is jsonb. Most of them didn't start that way. courses.title, lessons.title, lessons.content_markdown and challenges.instruction began…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...