Forum: Ruby on Rails command rake migration also runs #down method ?

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.
01b3d9e37307865fee8130ca7076acdd?d=identicon&s=25 Tuka Opaleye (tuka)
on 2006-04-25 15:05
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
 >>
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Kevin Olbrich (Guest)
on 2006-04-25 15:14
(Received via mailing list)
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 Opaleye wrote:
>
>Tuka
> == TestMigration: reverting
>===================================================
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails


_Kevin
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-04-25 19:36
> 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
01b3d9e37307865fee8130ca7076acdd?d=identicon&s=25 Tuka Opaleye (tuka)
on 2006-04-25 23:49
That would explain my dificulty with rake migration. thanks a lot.

Cheers,
Tuka
This topic is locked and can not be replied to.