Well, distillery does not run your migrations, it just bundles a release. And if edeliver runs your migrations (as it is the tool which deploys to your server and should set it up) depends on your configuration.
Without knowing your setup, we can only assume you are running a default setup, which simply doesn’t run migrations, as it can not assume there were any, since edeliver and distillery are agnostic to the libraries you use. You might use a different way to connect to your database, even you might not use a database at all, etc.
That’s a good point. So in the edeliver config file I used a script I saw on a blog post and simply added
mix ecto.create mix ecto.migrate
but I’m starting to suspect that may not be the correct way to migrate via production?
pre_erlang_clean_compile() {
status "Running phx.digest" # log output prepended with "----->"
__sync_remote " # runs the commands on the build host
# [ -f ~/.profile ] && source ~/.profile # load profile (optional)
source ~/.profile
# echo \$PATH # check if rbenv is in the path
mix ecto.create
mix ecto.migrate
set -e # fail if any command fails (recommended)
cd '$BUILD_AT/assets' # enter the build directory on the build host (required)
# prepare something
npm install
./node_modules/brunch/bin/brunch build --production
cd ..
mkdir -p priv/static # required by the phx.digest task
# run your custom task
APP='$APP' MIX_ENV='$TARGET_MIX_ENV' ECTO_REPOSITORY="myapp.Repo" PORT=443 $MIX_CMD phx.digest $SILENCE
"
}
This is my config from a recent project with automatic migration. I didn’t come up with it all but a can’t remember where I got it from either to link directly to the originator.
pre_erlang_get_and_update_deps() {
if [ "$TARGET_MIX_ENV" = "prod" ]; then
__sync_remote "
set -e
cd '$BUILD_AT'
mkdir -p priv/static
mix deps.get
cd '$BUILD_AT/assets'
npm install --no-warnings
npm run deploy --no-warnings
cd '$BUILD_AT'
APP='$APP' MIX_ENV='$TARGET_MIX_ENV' $MIX_CMD ecto.migrate $SILENCE
APP='$APP' MIX_ENV='$TARGET_MIX_ENV' $MIX_CMD phx.digest $SILENCE
"
fi
}