Very good question. Had me stumped so I dove into the rails source and pulled up database.rake. Now it’s more clear:
-
db:test:cloneis just a combination ofdb:schema:dumpanddb:test:load:task :clone => %w(db:schema:dump db:test:load) -
db:test:clone_structureuses the{rails_env}_structure.sqlfile:task :clone_structure => [ 'db:structure:dump', 'db:test:purge' ] do # skipped some code, here's what happens for MySQL: ActiveRecord::Base.establish_connection(:test) # ... IO.readlines("#{Rails.root}/db/#{Rails.env}_structure.sql").join.split("\n\n").each do |table| ActiveRecord::Base.connection.execute(table) end end -
db:test:loadis the same asdb:schema:load, but invokes it on the test database:task :load => 'db:test:purge' do ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) # ... db_namespace['schema:load'].invoke end -
db:test:preparealerts you if any migrations are pending, and if not, either runsdb:test:clone_structure(using the{rails_env}_structure.sqlfile) ordb:test:load(using theschema.rbfile), depending on the schema format (this is a little confusing to me, maybe someone else can expand on it):task :prepare => 'db:abort_if_pending_migrations' do # ... db_namespace[{ :sql => 'test:clone_structure', :ruby => 'test:load' }[ActiveRecord::Base.schema_format]].invoke end
Hope this clears it up! Again, going through the database.rake file is easy and will clear up any other questions you might have. That link goes to the line that is the beginning of the :test namespace.