migration.tri (1374B)
1 !import bd2c14d6db6b69308a5252a8e839705a55d30e815f012900b094315263e08d81 * 2 !import 3f70d95cf1bae0928ee89acd2a9e0cdd8287796efae32a9f08d33e3dd0149c55 as A 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 -- Select v1/v2 with the same input to compare the two target schemas. 9 -- A migration receipt can record the input identity, executable hash/export, 10 -- output identity and wire schema. Running this demo stays entirely local. 11 -- Records use [fieldName tag value]: 0 = text, 1 = natural, 2 = Boolean. 12 -- Base supplies arithmetic/Booleans; A.hostString? checks Unicode scalar text. 13 14 failure message = [["status" 0 "error"] ["message" 0 message]] 15 16 migrate version name email = case and? (A.hostString? name) (A.hostString? email) of 17 ^true = (case version of 18 1 = [["schemaVersion" 1 1] ["displayName" 0 name] ["email" 0 email]] 19 _ = [["schemaVersion" 1 2] ["displayName" 0 name] ["email" 0 email] 20 ["marketingOptIn" 2 false]]) 21 _ = failure "Name and email must be scalar text." 22 23 profile _ (t _) = failure "Expected a list." 24 profile _ [_ | (t _)] = failure "Expected a list." 25 profile version [name email] = migrate version name email 26 profile _ _ = failure "Expected [name email]." 27 28 v1 values = profile 1 values 29 v2 values = profile 2 values