Scripts
Z has a library of developer-side scripts, located in priv/scripts
. These scripts are like saved "console sessions" - jobs that we previously had to do developer-side, that had some chance of being repeated in the future.
You can run these scripts using mix run
from the root folder; for example:
mix run priv/scripts/2021.05.06.update_hsdb_image_sizes.exs
Conventions
Scripts are date-stamped, similar to Ecto
migrations. This is to help us with recalling when we ran a previous script, and also to provide some sort of organizational structure to what otherwise might just become a random pile.
Livebooks
You'll find some scripts that have been saved as Elixir Livebooks. You'll recognize them because they have a .livemd
file extension. These files can't be run with mix run
, but should be run from a livebook server.
The quickest way to set this up is:
- Install Livebook
- Run
livebook server
from the Z root folder. - Open up the server link that you see, eg.
http://localhost:8080/?token=x6ner4ykhpimfpzjas4i6yjbvlogmg4h
. - From within livebook, navigate to the
priv/scripts
folder and select the livebook you want to run. - Select "Runtime Settings" from the sidebar, and then use "Mix standalone" (or "Attached node") to connect to Z.
- If you want to connect the LiveBook to Z directly + run code from the perspective of your dev server, make sure to start the server with
iex --sname z --cookie z -S mix phx.server
and then connect from LiveBook using cookiez
and passwordz
.
- If you want to connect the LiveBook to Z directly + run code from the perspective of your dev server, make sure to start the server with
- You'll now be able to run your Livebook with full access to Z's codebase. Neat!