appengine-ruby icon indicating copy to clipboard operation
appengine-ruby copied to clipboard

[Question] Run migrations automatically on 'gcloud app deploy' ?

Open jamesst20 opened this issue 6 years ago • 2 comments

Hi,

Sorry in advance if it isn't the right place to ask.

I was wondering if it was possible to automatically run migrations on every deploy ? Currently I must run bundle exec rake appengine:exec -- bundle exec rake db:migrate after each deploy manually.

Thank you

jamesst20 avatar Jun 14 '19 13:06 jamesst20

This is a very good idea, and actually a pretty common request. App Engine doesn't provide any deploy hooks, but we could provide a rake task that does this (i.e. the rake task just does a gcloud deploy followed by a rake appengine:exec). Although you could also just write yourself a shell script.

dazuma avatar Jul 09 '19 00:07 dazuma

To solve this situation I use this entrypoint in app.yaml: entrypoint: bin/rails_with_migrations.sh server -u puma --port $PORT and the following script in bin with +x property:

#!/bin/bash
bundle exec rake db:migrate
if [ $? -eq 0 ]
then
  bundle exec rails $@
else
  echo "Failure: migrations failed, please check application logs for more details." >&2
  exit 1
fi

crivotz avatar Apr 18 '23 14:04 crivotz