rails
rails copied to clipboard
Add a `--db-prepare` option to run check and run migrations when booting the server
The current docker entrypoint will slow down starting rails server
because it will first load another Rails process to check and run database migrations (which is necessary because not all runtime platforms support deployment tasks):
https://github.com/rails/rails/blob/fc9ed119c718ea0654e4a5d2477d8391252cbe6b/railties/lib/rails/generators/rails/app/templates/docker-entrypoint.tt#L10-L12
It would be nice if something like a bin/rails --db-prepare
flag existed that could check for migrations (and run them) if necessary and only have to boot a single Rails app and thus boot the server faster.
While briefly talking through this with @matthewd, he imagined it might be able to work like this:
- Do a check if migrations are needed inline while booting the Rails server
- If there are pending migrations, run a subprocess (or fork, if possible) that would be equivalent to the
db:prepare
task.
We considered but didn't think it would be safe to also run the migrations in the same rails server
process because it's possible it could leak database connections or other state.