migration.tri (1396B)
1 !import bd2c14d6db6b69308a5252a8e839705a55d30e815f012900b094315263e08d81 * 2 !import 3f70d95cf1bae0928ee89acd2a9e0cdd8287796efae32a9f08d33e3dd0149c55 * 3 !export v1 4 !export v2 5 6 -- Archived profile v0: [name email]. v1: adds schemaVersion and displayName. 7 -- v2: also supplies marketingOptIn=false; existing data is preserved. 8 -- Try result = v1 ["James" "james@example.org"]. 9 -- Change v1 to v2 to compare the two target schemas. 10 -- A migration receipt can record the input identity, executable hash/export, 11 -- output identity and wire schema. Running this demo stays entirely local. 12 -- Records use [fieldName tag value]: 0 = text, 1 = natural, 2 = Boolean. 13 -- Base supplies arithmetic/Booleans; hostString? checks Unicode scalar text. 14 15 failure message = [["status" 0 "error"] ["message" 0 message]] 16 17 migrate version name email = case and? (hostString? name) (hostString? email) of 18 ^true = case version of 19 1 = [["schemaVersion" 1 1] ["displayName" 0 name] ["email" 0 email]] 20 _ = [["schemaVersion" 1 2] ["displayName" 0 name] ["email" 0 email] 21 ["marketingOptIn" 2 false]] 22 _ = failure "Name and email must be scalar text." 23 24 profile _ (t _) = failure "Expected a list." 25 profile _ [_ | (t _)] = failure "Expected a list." 26 profile version [name email] = migrate version name email 27 profile _ _ = failure "Expected [name email]." 28 29 v1 values = profile 1 values 30 v2 values = profile 2 values