Skip to content

Instantly share code, notes, and snippets.

@ejpcmac
Created September 28, 2018 20:39
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ejpcmac/c09d47dfa627c9503c01cdf0779af0f7 to your computer and use it in GitHub Desktop.
Setup script for Phoenix projects using Nix and PostgreSQL
#!/bin/sh
echo
if [ ! -d "deps" ] || [ ! "$(ls -A deps)" ]; then
printf "\e[32m=> Fetching dependencies and building the application...\e[0m\n\n"
echo "+ mix do deps.get, compile --verbose"
mix do deps.get, compile --verbose
echo
fi
if [ ! -d "$PGDATA" ]; then
printf "\e[32m=> Initialising the database in $PGDATA...\e[0m\n\n"
echo "+ initdb --no-locale --encoding=UTF-8"
initdb --no-locale --encoding=UTF-8
echo
fi
if [ ! -f "$PGDATA/postmaster.pid" ]; then
printf "\e[32m=> Starting PostgreSQL...\e[0m\n\n"
echo "+ pg_ctl -l \"$PGDATA/server.log\" start"
pg_ctl -l "$PGDATA/server.log" start
echo
fi
printf "\e[32m=> Creating the postgres user if necessary...\e[0m\n\n"
echo "+ createuser postgres --createdb --echo"
createuser postgres --createdb --echo
echo
set -e
printf "\e[32m=> Setting up the database...\e[0m\n\n"
echo "+ mix ecto.reset"
mix ecto.reset
echo
printf "\e[32m\e[1mThe project setup is complete!\e[0m\n\n"
printf "To start the application in an IEx shell, you can now run:\n\n"
printf " iex -S mix phx.server\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment