{"canonical_url":"https://engineer.company/portfolio/implemented-a-catalogue-driven-deep-merge/","content_markdown":"# Implemented a catalogue‑driven deep‑merge\n\nImplemented a catalogue‑driven deep‑merge for stored JSON preferences, preventing missing‑key crashes as the schema evolves.\n\n2025\n\n**Situation.** The platform stores JSON preferences — notification settings and the like — as a user's saved values laid over a set of defaults. The original merge did that at a single level. The problem shows up later: add a new key to the defaults, and rows saved before that key existed simply don't have it. Then some client code reads that field, gets undefined, and falls over — for exactly the users who've been around longest.\n\n**Task.** Evolving the preference schema had to be safe, so that adding a setting could never break the people who signed up before it existed.\n\n**Action.** The single‑level merge was replaced with a deep‑merge driven by the defaults as a catalogue. The defaults are treated as the authoritative list of every key that should exist; the user's stored values are merged recursively on top, so anything in the catalogue is guaranteed to come out present, whether or not it was in the saved blob. Add a key to the defaults and it appears in every existing row's effective preferences automatically, nested keys included. It rolled in through a migration so existing data got the benefit straight away rather than waiting to be rewritten.\n\n**Result.** Preferences can grow without fear. Adding a setting no longer risks an undefined‑field crash in the client, and the frontend stopped needing defensive checks scattered around every place it reads a preference. It also gave the rest of the platform a dependable way to extend any stored‑JSON blob — the pattern, not just the one fix.\n\n---\n\n- Role: Database Engineer\n- Categories: [Backend Engineering](https://data.engineer.company/categories/backend/), [Databases](https://data.engineer.company/categories/databases/), [PostgreSQL](https://data.engineer.company/categories/postgresql/), [Data Governance](https://data.engineer.company/categories/data-governance/), [Migrations \u0026 Modernization](https://data.engineer.company/categories/migration/)\n- Services: [Backend \u0026 API Development](https://data.engineer.company/services/backend-development/), [Database Design \u0026 Modeling](https://data.engineer.company/services/database-design/), [Data Governance \u0026 Quality](https://data.engineer.company/services/data-governance/)\n\n\u003chttps://engineer.company/portfolio/implemented-a-catalogue-driven-deep-merge/\u003e\n","date_modified":"2026-10-20T21:59:50Z","description":"Implemented a catalogue-driven deep-merge for stored JSON preferences, preventing missing-key crashes as the schema evolves.","formats":{"gemtext":"https://data.engineer.company/portfolio/implemented-a-catalogue-driven-deep-merge/index.gmi","gopher":"https://data.engineer.company/portfolio/implemented-a-catalogue-driven-deep-merge/gophermap","html":"https://data.engineer.company/portfolio/implemented-a-catalogue-driven-deep-merge/","json":"https://data.engineer.company/portfolio/implemented-a-catalogue-driven-deep-merge/index.json","markdown":"https://data.engineer.company/portfolio/implemented-a-catalogue-driven-deep-merge/index.md","pdf":"https://data.engineer.company/portfolio/implemented-a-catalogue-driven-deep-merge/index.pdf"},"kind":"page","language":"en","title":"Implemented a catalogue-driven deep-merge","url":"https://data.engineer.company/portfolio/implemented-a-catalogue-driven-deep-merge/","version":1}