I found a solution in the openshift docs, which is actually not even valid sh. Here is my version.
if echo "use $OPENSHIFT_APP_NAME; show tables" | mysql | grep schema_migrations 2>&1 > /dev/null
then
bundle exec rake db:migrate RAILS_ENV="production"
else
bundle exec rake db:setup RAILS_ENV="production"
fi
If you are using postgres, here is a similar command
if echo "\c $PGDATABASE; \dt" | psql | grep schema_migrations 2>&1 >/dev/null
then
bundle exec rake db:migrate RAILS_ENV="production"
else
bundle exec rake db:setup RAILS_ENV="production"
fi
I'm sure there is a similar environment variable as $PGDATABASE
for mysql that you can use instead of $OPENSHIFT_APP_NAME
. You can find it by running rhc ssh -a app-name
, then running env
to get a list of the environment variables.