What does rake db:test:prepare actually do?
Ruby on-RailsRubyRuby on-Rails Problem Overview
I am following the rails tutorial videos and I can't figure out what the db:test:prepare
command actually does. Can someone provide an explanation?
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
> The rake db:migrate above runs any pending migrations on the > development environment and updates db/schema.rb. The rake > db:test:load recreates the test database from the current > db/schema.rb. On subsequent attempts, it is a good idea to first run > db:test:prepare, as it first checks for pending migrations and warns > you appropriately.
-- http://guides.rubyonrails.org/testing.html
Basically it handles cloning the database so you don't have to run the migrations against test to update the test database.
Solution 2 - Ruby on-Rails
Specifically, rake db:test:prepare
will do the following:
- Check for pending migrations and,
- load the test schema
That is, it will look your db/schema.rb
file to determine if any migrations that exist in your project that have not been run. Assuming there are no outstanding migrations, it will then empty the database and reload it based on the contents of the db/schema.rb
file.
Solution 3 - Ruby on-Rails
rake db:test:prepare is a good solution for PG issues like this.
“PG::UndefinedTable: ERROR: relation does not exist” with a correct Rails naming and convention" where I couldn't just execute rake db:migrate RAILS_ENV=production
When, for example you can't create test database for a bug discussed here: "PG undefinedtable error relation users does not exist"
All arround this error "PG::UndefinedTable: ERROR: relation xxxxx does not exist”