Rake migrate VERSION=0 doesn't appear to execute


#1

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


#2

On 5/25/06, Wes G. removed_email_address@domain.invalid 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


#3

Wes G. wrote:

Curtis S. wrote:

On 5/25/06, Wes G. removed_email_address@domain.invalid 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,
Wes

Yep, 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


#4

On 5/25/06, Wes G. removed_email_address@domain.invalid 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. :slight_smile:
Use them, Know them, Love them…


#5

Curtis S. wrote:

On 5/25/06, Wes G. removed_email_address@domain.invalid 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,
Wes


#6

On Thu, 2006-05-25 at 17:59 +0200, Wes G. wrote:

** Invoke environment
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