Skip to content

Instantly share code, notes, and snippets.

@sirlensalot
Created August 31, 2021 17:10
Show Gist options
  • Save sirlensalot/2a333ff8d53471774a6aedfb90b4eb10 to your computer and use it in GitHub Desktop.
Save sirlensalot/2a333ff8d53471774a6aedfb90b4eb10 to your computer and use it in GitHub Desktop.
Pact schema upgrade
(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