Skip to Content
Docker for Rails Developers
book

Docker for Rails Developers

by Rob Isenberg
February 2019
Intermediate to advanced
240 pages
5h 25m
English
Pragmatic Bookshelf
Content preview from Docker for Rails Developers

Migrating the Database

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn Rails 6: Accelerated Web Development with Ruby on Rails

Learn Rails 6: Accelerated Web Development with Ruby on Rails

Adam Notodikromo
Mastering Ruby Closures

Mastering Ruby Closures

Benjamin Tan Wei Hao

Publisher Resources

ISBN: 9781680506730Errata Page