February 2019
Intermediate to advanced
240 pages
5h 25m
English
We saw here that the Postgres image automatically creates the default database if it doesn’t exist. However, currently nothing ensures that the migrations have been run; in development, we just did this manually. We need to ensure that our app has a fully migrated database when it launches.
One way you might think of achieving this is with the entrypoint concept we introduced to solve the server PID issue. We already have a docker-entrypoint.sh file that is run just prior to launching our app; this might lead you to try migrating the database as follows:
| | #!/bin/sh |
| | |
| | set -e |
| | |
| | if [ -f tmp/pids/server.pid ]; then |
| | rm tmp/pids/server.pid |
| | fi |
| | |
| | |
| » | # BAD IDEA... |
| » | bin/rails db:migrate |
| | |
| | exec "$@" |
Although ...