WEBVTT

00:00:00.500 --> 00:00:03.208
This app is deployed with root memory version one.

00:00:04.108 --> 00:00:08.106
The root saves no fields, and it has one child, Scores.

00:00:09.004 --> 00:00:11.153
We want the root to save a revision number.

00:00:12.051 --> 00:00:15.241
Version one is shipped, so its file stays as it is.

00:00:16.140 --> 00:00:19.252
Version two is a new file with the complete declaration.

00:00:20.150 --> 00:00:22.246
Data now has the revision field.

00:00:23.145 --> 00:00:26.283
The children are written out again, and the Scores slot still

00:00:26.296 --> 00:00:27.728
names Scores version one.

00:00:28.627 --> 00:00:29.720
The root changed.

00:00:30.619 --> 00:00:33.418
Scores did not, so its version number stays.

00:00:34.317 --> 00:00:37.207
The selector now exports version two as current.

00:00:38.106 --> 00:00:39.838
Both modules stay in the source.

00:00:40.736 --> 00:00:43.692
Service code keeps saying current and follows along.

00:00:44.590 --> 00:00:47.025
Version one remains for the converter to read.

00:00:49.167 --> 00:00:51.562
The converter lives in the root's memory folder.

00:00:52.463 --> 00:00:55.874
It takes the version one root and returns the version two root.

00:00:56.773 --> 00:01:00.236
Its first closure receives the old data, which was empty, and

00:01:00.249 --> 00:01:02.502
returns the new data with revision two.

00:01:03.400 --> 00:01:05.549
Its second closure handles the children.

00:01:06.447 --> 00:01:09.416
It takes Scores out of the old slot and attaches it to the new

00:01:09.429 --> 00:01:09.846
one.

00:01:10.744 --> 00:01:12.880
The scores themselves are never touched.

00:01:13.778 --> 00:01:15.288
Two more edits connect it.

00:01:16.187 --> 00:01:19.182
The root attribute lists version one under previous.

00:01:20.080 --> 00:01:22.880
That is the only older contract this build will accept.

00:01:23.778 --> 00:01:27.202
Then open, which restore calls, asks which root the canister

00:01:27.215 --> 00:01:27.827
saved.

00:01:28.726 --> 00:01:31.278
If it is version one, it runs the converter.

00:01:32.176 --> 00:01:34.533
Otherwise it opens version two directly.

00:01:35.432 --> 00:01:37.919
Either way it ends by binding the services.

00:01:40.067 --> 00:01:42.593
A native test covers the converter itself.

00:01:43.493 --> 00:01:47.295
It installs a version one root by hand, saves ninety-one under

00:01:47.308 --> 00:01:49.157
key seven, and calls open.

00:01:50.056 --> 00:01:53.324
Afterward the Scores module is the very same one, key seven

00:01:53.337 --> 00:01:56.410
still holds ninety-one, and the generation is two.

00:01:57.308 --> 00:02:00.615
On PocketIC the test starts from an installed version one with

00:02:00.629 --> 00:02:01.592
two values.

00:02:02.490 --> 00:02:05.563
A version two build that forgot to declare its predecessor is

00:02:05.576 --> 00:02:06.332
refused.

00:02:07.230 --> 00:02:10.707
Another build converts successfully and then fails in its restore

00:02:10.720 --> 00:02:11.358
callback.

00:02:12.256 --> 00:02:13.936
The whole upgrade is undone.

00:02:14.834 --> 00:02:18.389
The canister is version one again, with generation one and both

00:02:18.402 --> 00:02:19.079
values.

00:02:19.977 --> 00:02:22.282
The proper version two build upgrades.

00:02:23.181 --> 00:02:26.592
Generation is two, and keys seven and eight still hold their

00:02:26.605 --> 00:02:27.334
values.

00:02:28.233 --> 00:02:30.876
From here the old build is no longer accepted.

00:02:31.774 --> 00:02:35.199
The test tries to install version one again and it is refused.

00:02:36.097 --> 00:02:39.743
Later version two releases upgrade normally, and the app stays

00:02:39.756 --> 00:02:40.342
writable.

00:02:41.240 --> 00:02:43.011
One planning rule remains.

00:02:43.910 --> 00:02:46.970
The whole conversion runs inside the single upgrade.

00:02:47.868 --> 00:02:50.980
There is no background migration that continues afterward.

00:02:51.879 --> 00:02:55.368
So design a revision that fits, and move unchanged collections

00:02:55.381 --> 00:02:59.457
across whole, as this converter moved Scores, in place of rebuilding

00:02:59.470 --> 00:03:00.524
them row by row.

