GoogleCloudPlatform / appengine-ruby

Optional integration library for the Ruby runtime for Google App Engine
Apache License 2.0
53 stars 21 forks source link

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

Open jamesst20 opened 5 years ago

jamesst20 commented 5 years ago

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

dazuma commented 5 years ago

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.

crivotz commented 1 year ago

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