Created
August 31, 2021 17:10
-
-
Save sirlensalot/2a333ff8d53471774a6aedfb90b4eb10 to your computer and use it in GitHub Desktop.
Pact schema upgrade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(begin-tx) | |
(module m g | |
(defcap g () true) | |
(defschema s | |
a:string | |
) | |
(deftable t:{s}) | |
(defun add (k:string a:string) | |
(insert t k { 'a: a }) | |
) | |
(defun get-all:[object{s}] () | |
(select t (constantly true)) | |
) | |
) | |
(create-table t) | |
(add "1" "Bob") | |
(add "2" "Alice") | |
(get-all) | |
(commit-tx) | |
(begin-tx) | |
(module m g | |
(defcap g () true) | |
(defschema s | |
a:string | |
i:integer | |
) | |
(deftable t:{s}) | |
(defun migrate (k:string) | |
(let ((old (read t k))) | |
(update t k { 'i: 0 }) | |
[old,(read t k)]) | |
) | |
) | |
(map (migrate) (keys t)) | |
(commit-tx) | |
(begin-tx) | |
(module m g | |
(defcap g () true) | |
(defschema s | |
a:string | |
i:integer | |
) | |
(deftable t:{s}) | |
(defun add (k:string a:string) | |
(insert t k { 'a: a }) | |
) | |
(defun get-all:[object{s}] () | |
(select t (constantly true)) | |
) | |
) | |
(get-all) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment