Skip to content

Commit

Permalink
Refactor database set up with new Rails 6 method
Browse files Browse the repository at this point in the history
* `rake db:prepare` looks to be equivalant. It runs the migration, if no database can be found it then seeks to create one. rails/rails#35768
* Given that this method is now tested as part of rails we have more confidence in the previous bug that reset the database despite it existing. Presumably this was caused by an error in how we were checking if a migration was pending so we should try removing our production guard.
  • Loading branch information
tahb committed Jul 24, 2020
1 parent 4f30309 commit b9bdeeb
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,10 @@ echo "ENTRYPOINT: Starting docker entrypoint…"

setup_database()
{
echo "ENTRYPOINT: Checking database setup is up-to-date…"
# Rails will throw an error if no database exists"
# PG::ConnectionBad: FATAL: database "roda-development" does not exist
if rake db:migrate:status &> /dev/null; then
echo "ENTRYPOINT: Database found, running db:migrate…"
rake db:migrate
else
if [ "$RAILS_ENV" == "production" ]; then
echo "ENTRYPOINT: Environment is production, doing nothing."
else
echo "ENTRYPOINT: Environment is in non-production, attempting to automatically create the database…"
echo "ENTRYPOINT: Running db:create db:schema:load…"
rake db:create db:environment:set db:schema:load
fi
fi
echo "ENTRYPOINT: Finished database setup"
echo "ENTRYPOINT: Running rake db:prepare…"
# Migrate the database and if one doesn't exist then create one
bundle exec rake db:prepare
echo "ENTRYPOINT: Finished database setup."
}

if [ -z ${DATABASE_URL+x} ]; then echo "Skipping database setup"; else setup_database; fi
Expand Down

0 comments on commit b9bdeeb

Please sign in to comment.