Skip to content

Commit 94cf517

Browse files
committedFeb 12, 2019
Moremore schema migration prose.
I think this is as much as I can write about this for now. Regarding that last bit about not having total migration magic: I'd certainly be neato to offer more auto-migration tools, based on perhaps a "patch"ing approach as outlined in ipld/js-ipld#66 (comment) , or on generalized recursion schemes, or a combination. However... that's a tad downstream of the present ;) Signed-off-by: Eric Myhre <[email protected]>
1 parent deeeacc commit 94cf517

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
 

‎doc/schema.md

+33
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,36 @@ other forms of versioning; it's essentially the same as using explicit labels.
244244

245245
### Actually Migrating!
246246

247+
... Okay, this was a little bit of bait-and-switch.
248+
IPLD Schemas aren't completely magic.
249+
250+
Some part of migration is inevitably left up to application logic.
251+
Almost by definition, "a process to map data into the format of data we want"
252+
is at its most general going to be a turing-complete operation.
253+
254+
However, IPLD can still help: the relationship between the Data Model versus
255+
the Schema provides a foundation for writing maintainable migrations.
256+
257+
Any migration logic can be expressed as a function from `Node` to `Node`.
258+
These nodes may each be checking Schema validity -- against two different
259+
schemas! -- but the code for transposing data from one node to the other
260+
can operate entirely within Data Model. The result is the ability to write
261+
code that's effectively handling multiple disjoin type systems... without
262+
any real issues.
263+
264+
Thus, a valid strategy for longlived application design is to handle each
265+
major change to a schema by copying/forking the current one; keeping it
266+
around for use as a recognizer for old versions of data; and writing a
267+
quick function that can flip data from the old schema format to the new one.
268+
When parsing data, try the newer schema first; if it's rejected, try the old
269+
one, and use the migration function as necessary.
270+
271+
If you're using codegen based on the schema, note that you'll probably only
272+
need to use codegen for the most recent / most preferred version of the schema.
273+
(This is a good thing! We wouldn't want tons of generated code per version
274+
to start stacking up in our repos.)
275+
Parsing of data for other versions can be handled by ipldcbor.Node or other
276+
such implementations which are optimized for handling serial data; the
277+
migration function is a natural place to build the codegenerated native typed
278+
Nodes, and so each half of the process can easily use the Node implementation
279+
that is best suited.

0 commit comments

Comments
 (0)
Please sign in to comment.