Articles
Patterns 1 min 118

Dictionary Pattern: Making Any Entity Flexible Without Migrations

How to add arbitrary fields to any model via JSONB field_schema. No migrations, with validation and AI parsing.

The Problem

An HR system for an IT startup and for a septic service company are different worlds. The startup needs a "GitHub username" field, a clinic needs "License number", a transport company needs "ADR permit category."

The classic approach — a migration for every field — doesn't scale.

Solution: Dictionary with field_schema

A Dictionary model with kind: :field_schema stores a JSON schema describing custom fields per entity type per company. One custom_data JSONB column on the target model holds the values.

How it works

  1. HR defines fields in the admin UI (or AI generates them via company_bootstrap)
  2. Forms auto-render based on the schema (text, select, date, number, boolean, textarea)
  3. Validation runs against the schema — required fields, regex patterns
  4. AI agents parse documents against the same schema

Key benefit

Zero migrations. HR configures fields in UI. Validation, AI parsing, and audit all follow the schema automatically. The pattern is reused in Triage for custom fields per ticket type.

Comments (0)