TBD54566975 / ftl

FTL - Towards a 𝝺-calculus for large-scale systems
https://tbd54566975.github.io/ftl/
Apache License 2.0
22 stars 7 forks source link

Change backend encoding to include type+version information? #2493

Open alecthomas opened 3 months ago

alecthomas commented 3 months ago

As we start thinking about data migration more and more, one idea that came up was to encode the type+version along with values.

Currently a data type like:

data User { // v1
  name String
  age Int
}

Will be encoded as JSON like so:

{"name":"Alice","age":30}

But if the data structure is changed to:

data User { // v2
  username String
}

The old version of the struct will not be able to be decoded into the new version, and will fail with an arbitrary decoding error.

If we instead encoded the type+version into the value:

{
  "ver": "v1",
  "t": "module.User",
  "d": {
    "name": "Alice",
    "age": 30
  }
}

We would be able to give a much more useful error, or perform automatic migrations via inline "migration functions".

deniseli commented 2 months ago

Notes: