Skip to content

Allow retain_unlisted_types_on_load: :all - #144

Open
themiguelamador wants to merge 1 commit into
mathieuprog:masterfrom
themiguelamador:feat/retain-all-unlisted-types
Open

themiguelamador wants to merge 1 commit into
mathieuprog:masterfrom
themiguelamador:feat/retain-all-unlisted-types

Conversation

@themiguelamador

Copy link
Copy Markdown

Closes #142.

:retain_unlisted_types_on_load takes a list of type names that load as raw maps instead of raising. This PR also accepts :all, which retains every type the field doesn't know. That covers types a codebase can't list in advance:

  • Rolling deploys: several application versions share a database, and a newer release writes a type the older one doesn't ship. The older nodes then crash on any read that loads that row.
  • Removed types: a type is removed from the code without migrating its rows.

Behaviour

  • :all: any type not in types loads as the raw map. Known types still load as their structs.
  • A list keeps its current meaning.
  • The options validator accepts :all or a list of atoms, and its error message says so.
  • The README documents :all, and notes that a retained raw map can't be dumped back, so such records are read-only.

Tests

Four tests on PolymorphicEmbed.load/3:

  • :all loads unknown types as raw maps;
  • :all still loads a known type as its struct;
  • a list still retains only the listed types;
  • the validator rejects any other value.

The first, second and fourth fail without the change. mix test: 81 passed, on Elixir 1.20.3 / OTP 28.

We've been running this exact patch in production (vendored 5.0.6) to keep reads alive across deploys.

`:retain_unlisted_types_on_load` takes a list of type names to load as raw
maps instead of raising. `:all` retains every type the field does not know,
for types a codebase cannot list in advance: several application versions
sharing a database during a rolling deploy (a newer release writes a type the
older one does not ship), or a type removed without migrating its rows.

Known types still load as their structs, and a list keeps its current meaning.

Closes mathieuprog#142.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow retain_unlisted_types_on_load: :all for types unknown to the running build

1 participant