Wes Gamble
2006-May-25 16:00 UTC
[Rails] rake migrate VERSION=0 doesn''t appear to execute
All, I''ve decided to jump into Migrations before I get too far along on the DB side of things. I already have some tables built, and I went ahead and built the migration that would have created them from scratch, and I made sure that there was a self.down section to drop them. I wanted to verify that I could roll back so I figured I would use rake to drop these pre-existing tables before I recreated them. Sure enough, if I run rake migrate, I get the error that says the tables already exist. Great - that means rake can find my migration and the "up" section is probably valid. However, if I do rake migrate VERSION=0 which I am understanding should undo the first migration, nothing happens. Here is the output of a trace: C:\eclipse\workspace\eSimplyOnlineRails>rake -t migrate VERSION=0 (in C:/eclipse/workspace/eSimplyOnlineRails) ** Invoke migrate (first_time) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate ** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump ** Execute migrate but my tables aren''t dropped. Here''s my migration: class CreateInitialSchema < ActiveRecord::Migration def self.up ...creates a bunch of tables end def self.down drop_table :target_lists drop_table :jobs drop_table :stylesheets drop_table :images drop_table :documents end end Does rake migrate VERSION=0 rollback the very FIRST migration? What am I doing wrong? Thanks, Wes -- Posted via http://www.ruby-forum.com/.
On 5/25/06, Wes Gamble <weyus@att.net> wrote:> All, > > Sure enough, if I run rake migrate, I get the error that says the tables > already exist. Great - that means rake can find my migration and the > "up" section is probably valid.Your problem is probably that the tables already do exist. This makes Migrate error out before completing. If it were successful, it would set the version for the migration in the database. This probably has not been set (or is 0) so the Migrate Version=0 thinks it is already in that state. Two options. Delete the tables, then run the initial Migration so it''s populated fully. Jump into the db itself and set the version value to 1 manually in the migrations table (sorry I should know the table name offhand, but don''t...it''s obvious though). -Curtis
Wes Gamble
2006-May-25 16:25 UTC
[Rails] Re: rake migrate VERSION=0 doesn''t appear to execute
Curtis Spendlove wrote:> On 5/25/06, Wes Gamble <weyus@att.net> wrote: >> All, >> >> Sure enough, if I run rake migrate, I get the error that says the tables >> already exist. Great - that means rake can find my migration and the >> "up" section is probably valid. > > Your problem is probably that the tables already do exist. This makes > Migrate error out before completing. If it were successful, it would > set the version for the migration in the database. This probably has > not been set (or is 0) so the Migrate Version=0 thinks it is already > in that state. > > Two options. Delete the tables, then run the initial Migration so > it''s populated fully. Jump into the db itself and set the version > value to 1 manually in the migrations table (sorry I should know the > table name offhand, but don''t...it''s obvious though). > > -CurtisCurtis, That makes sense. Thanks, Wes -- Posted via http://www.ruby-forum.com/.
Wes Gamble
2006-May-25 16:28 UTC
[Rails] Re: rake migrate VERSION=0 doesn''t appear to execute
Wes Gamble wrote:> Curtis Spendlove wrote: >> On 5/25/06, Wes Gamble <weyus@att.net> wrote: >>> All, >>> >>> Sure enough, if I run rake migrate, I get the error that says the tables >>> already exist. Great - that means rake can find my migration and the >>> "up" section is probably valid. >> >> Your problem is probably that the tables already do exist. This makes >> Migrate error out before completing. If it were successful, it would >> set the version for the migration in the database. This probably has >> not been set (or is 0) so the Migrate Version=0 thinks it is already >> in that state. >> >> Two options. Delete the tables, then run the initial Migration so >> it''s populated fully. Jump into the db itself and set the version >> value to 1 manually in the migrations table (sorry I should know the >> table name offhand, but don''t...it''s obvious though). >> >> -Curtis > > Curtis, > > That makes sense. > > Thanks, > WesYep, that was it. I modified the schema_info table to set the current version to 1 and then was able to revert. I''m happy - looks like Migrations works well so I''m glad to be able to integrate it into my experience and move on :). Wes -- Posted via http://www.ruby-forum.com/.
Curtis
2006-May-25 16:41 UTC
[Rails] Re: rake migrate VERSION=0 doesn''t appear to execute
On 5/25/06, Wes Gamble <weyus@att.net> wrote:> I''m happy - looks like Migrations works well so I''m glad to be able to > integrate it into my experience and move on :).Migrations are The Big Electron''s gift to database versioning. :) Use them, Know them, Love them...
Craig White
2006-May-25 18:56 UTC
[Rails] rake migrate VERSION=0 doesn''t appear to execute
On Thu, 2006-05-25 at 17:59 +0200, Wes Gamble wrote:> All, > > I''ve decided to jump into Migrations before I get too far along on the > DB side of things. > > I already have some tables built, and I went ahead and built the > migration that would have created them from scratch, and I made sure > that there was a self.down section to drop them. I wanted to verify > that I could roll back so I figured I would use rake to drop these > pre-existing tables before I recreated them. > > Sure enough, if I run rake migrate, I get the error that says the tables > already exist. Great - that means rake can find my migration and the > "up" section is probably valid. > > However, if I do > > rake migrate VERSION=0 > > which I am understanding should undo the first migration, nothing > happens. > > Here is the output of a trace: > > C:\eclipse\workspace\eSimplyOnlineRails>rake -t migrate VERSION=0 > (in C:/eclipse/workspace/eSimplyOnlineRails) > ** Invoke migrate (first_time) > ** Invoke db:migrate (first_time) > ** Invoke environment (first_time) > ** Execute environment > ** Execute db:migrate > ** Invoke db:schema:dump (first_time) > ** Invoke environment > ** Execute db:schema:dump > ** Execute migrate > > but my tables aren''t dropped. > > Here''s my migration: > > class CreateInitialSchema < ActiveRecord::Migration > def self.up > ...creates a bunch of tables > end > > def self.down > drop_table :target_lists > drop_table :jobs > drop_table :stylesheets > drop_table :images > drop_table :documents > end > end > > Does rake migrate VERSION=0 rollback the very FIRST migration? > > What am I doing wrong?---- I can''t answer the question but I never bothered to try because the first schema dump I did, I copied into the first migration file and I was done. That was certainly capable of creating the ''testing'' db and the ''production'' db''s so I know it worked so going back to ''0'' never seemed to be an issue Craig