Command rake migration also runs #down method?

Hi,

i am new to rails and trying to understand the migrate feature of rake

whenever I call “rake migrate”, i understand it call all the latest
version of a given of given migrate files.

Now when these files are executed, id the #down method called and then
the #up ? or must i explicitly call the #down method from rake. If yes
how do i do that from rake ?

I experimented with rake migrate and could not update my database table
i.e. chage a field from varchar(200) to varchar(200). i had to resort to
the console commands appended (see below) for it to work.

Also say I have migration scripts of different versions say for table1
it is version 5, table 7 version 4 etc
if I run rake migrate will it run both v5 for both tables or will it run
v4 for one and v5 for the other ? This is still not clear to me…

TIA,
Tuka

C:\TDV>ruby script/console
Loading development environment.

require ‘db/migrate/001_test_migration.rb’
=> true

TestMigration.down
== TestMigration: reverting
===================================================
– drop_table(:migration_test)
-> 0.0900s
== TestMigration: reverted (0.0900s)
==========================================

=> nil

TestMigration.up
== TestMigration: migrating
===================================================
– create_table(:migration_test)
-> 0.1200s
== TestMigration: migrated (0.1200s)
==========================================

=> nil

Here’s the way it is supposed to work.

  1. Rake looks at your database, there should be a table there that
    contains one column and one row that indicates the current version of
    the database schema

  2. Rake will then look through your migrations folder and looks at the
    number in the migration file names.

  3. For each file with a number greater than the current database schema,
    rake will call ‘up’

  4. When you are degrading to an earlier version, rake will call ‘down’
    for each migration file until the database schema version matches the
    migration file number.

The database only has one version number, which is the accumulation of
all the migrations up to that point. In many ways it is similar to
subversion’s revision number.

On Tuesday, April 25, 2006, at 3:05 PM, Tuka O. wrote:

Tuka
== TestMigration: reverting

Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

_Kevin

That would explain my dificulty with rake migration. thanks a lot.

Cheers,
Tuka

Now when these files are executed, id the #down method called and then
the #up ? or must i explicitly call the #down method from rake. If yes
how do i do that from rake ?

Down method should only be called when you are migrating to an earlier
version of the schema via:

rake migrate VERSION=12