Forum: Ruby on Rails rake migrate VERSION=0 doesn't appear to execute

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-05-25 17:59
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
39c5254d0a798765f37ac215fa6e0fc7?d=identicon&s=25 Curtis Spendlove (cuspendlove)
on 2006-05-25 18:22
(Received via mailing list)
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
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-05-25 18:25
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,
Wes
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-05-25 18:26
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,
> 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
39c5254d0a798765f37ac215fa6e0fc7?d=identicon&s=25 Curtis Spendlove (cuspendlove)
on 2006-05-25 18:41
(Received via mailing list)
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...
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-05-25 20:59
(Received via mailing list)
On Thu, 2006-05-25 at 17:59 +0200, Wes Gamble 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
This topic is locked and can not be replied to.