Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using rake db:migrate inside another task leaves pending migrations

I'm new to rake and I'm trying to find my way in automating some tasks. So I wrote my first rake task and failed:

namespace :app do
  desc "Leaves application like new"
  task :reset => :environment do
    Rake::Task['db:drop:all'].invoke
    Rake::Task['db:create:all'].invoke
    Rake::Task['db:migrate'].invoke
    Rake::Task['db:seed'].invoke
  end
end

I'd like to know why this isn't working. After calling:

rake app:reset

everything runs fine, I can see the migration messages on screen, like this:

==  CreateGalerias: migrating =================================================
-- create_table(:galerias)
NOTICE:  CREATE TABLE will create implicit sequence "galerias_id_seq" for serial column "galerias.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "galerias_pkey" for table "galerias"
   -> 0.1191s
==  CreateGalerias: migrated (0.1194s) ========================================

But, at the end I get this message:

You have 11 pending migrations:
  20110704052637 CreatePersonas
  20110709100632 CreateOrganizaciones
  20110709100646 CreateEventos
  20110816102451 CreateMembresias
  20110816155851 CreateCelebraciones
  20110822135820 ActsAsTaggableOnMigration
  20120410063100 CreateDocumentos
  20120507200516 CreateUsuarios
  20120515214226 ActivaUnnaccent
  20120516091228 CreateGalerias
  20120517004708 SetupHstore
Run `rake db:migrate` to update your database then try again.

Didn't it just migrated the database? why is it complaining about it?

like image 844
zenw0lf Avatar asked Nov 03 '22 23:11

zenw0lf


1 Answers

Keep in mind that db:drop:all and db:create:all operate on all environments, and db:migrate and db:seed do not, so you are probably migrating in an unintended environment. Try changing db:drop:all to db:drop and db:create:all to db:create, and run the task specifying a particular environment like:

rake RAILS_ENV=production app:reset
like image 94
Mike Auclair Avatar answered Nov 10 '22 14:11

Mike Auclair