Skip to content

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

Open

Description

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".

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

Metadata

Assignees

No one assigned

    Labels

    techdebtIssue is technical debt

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions