Deploy Missing Piece
-
Need for distillery to run migrations on deploy
- We need to create release tasks that will go in the root of lib.
- That will have a migration and / or seed function in it.
- Then in the rel/config.exs we a list of tuples that have the task command, what we want to refer to it as, and the the shell script that we want it to run.
- Remember mix isn’t installed on the prod machine!
- the shell script just calls bin/postit command Elixir.Postit.ReleaseTasks migrate
- Then we, to run migration on app launch for new builds, back in rel/config.ex we add set post_start_hooks: "rel/hooks/post_start" to env prod. in this directory we have a single shell script that will use nodetool to ping when the, not app, but BEAM? is up and running, and then run the migration.
#!/usr/bin/env bash set +e while true; do nodetool ping EXIT_CODE=$? if [[ ${EXIT_CODE} -eq 0 ]]; then echo "Application is up!" break fi done set -e echo "Running migrations" bin/postit command Elixir.Release.Tasks migrate echo "Migrations run successfully" -
It’s great that I had the command correct in the this write up.
- bc i didn’t in the post_start script or the set commands script
- currently it’s in both to see which if both run?
Custom commands give you a lot of power to express potentially complex operations as a terse statement. I would encourage you to use them for these types of tasks rather than using the raw rpc and eval tasks!
Missing Model Features
- Posts will need to be a many-to-one to users or ‘authors’
- mix ecto.gen.migration update_posts_with_user_relationship
- why? so we can list posts by author. ?♂️
- post’s are not editable. once published, it’s done
- auto saving versions for undo?
- would that be a Postgres implementation? Where would that line be?
build_assoc(struct, assoc, attributes \ %{}) Builds a struct from the given assoc in model.
If the relationship is a has_one or has_many and the key is set in the given model, the key will automatically be set in the built association / Ecto Documentation
def change do alter table("posts") do add: user_id, :uuid end
- We’re adding a column to our posts table user_id with data type uuid, as it should be a unique identifier? But I don’t really know, bc it’s coming from auth0. Still happy I didn’t role my own.
- Option B is we could reallocate the user table from auth0 i believe to be in our own database and then create a user scheme to get the info we need from it. That might be an option for another day?
- Search: elixir pattern match 2 string keys
def create(conn, %{"post" => post_params}) do case Posting.create_post(post_params) do {:ok, post} ->
Resources
Follow
- JavaScript to Elm
- Jesse Tomchak