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:

  1. Install Livebook
  2. Run livebook server from the Z root folder.
  3. Open up the server link that you see, eg. http://localhost:8080/?token=x6ner4ykhpimfpzjas4i6yjbvlogmg4h.
  4. From within livebook, navigate to the priv/scripts folder and select the livebook you want to run.
  5. 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 cookie z and password z.
  6. You'll now be able to run your Livebook with full access to Z's codebase. Neat!