Run single migration (not newest) in Yii
Asked Answered
D

2

9

I have few migrations files.How can I run single migration down or up, if this migration isn't the newest, but some steps in the migrations history?

When I run yiic migrate up 1, it runs the latest migration. Running migration command using migration version as parameter also doesn't help.

Dickman answered 22/2, 2014 at 8:27 Comment(0)
G
8

Please check documentation about redoing-migrations section:

yiic migrate redo [step]

If you want to undo/redo only one specific migration in your migration history. You have to modify your migration history :

yiic migrate mark 101129_185401
yiic migrate redo
Gunflint answered 22/2, 2014 at 8:36 Comment(4)
But I want to revert and apply just specified migration not first last or 3 latestDickman
Ok I get your point. I would do yiic migrate mark idOfMyMigration to go to the desired migration then I would be able to migrate up/down starting from the migration I want.Gunflint
This will set history mark to given point and will indeed redo only one, specific migration. But, executing yiic migrate will cause YiiC to attempt to execute all migrations from given mark, up the newest one. One must remember to "reset" history mark to the newest migration, after redoing that particular one.Dodecagon
Seems like the correct syntax in 2020 is yii migrate/mark 101129_185401 (note the /)Harday
F
0

In Yii 1.1 - to redo just one historic migration you need a few steps.

  1. Make a note of the full name of the latest migration you have run (the last displayed in your migrations table) and the full name of the migration you want to run again:

m210905_112345_to_run_again
m210906_125400_latest_one

  1. Go back in time:
    yiic migrate mark m210905_112345_to_run_again

  2. Run that one migration again
    yiic migrate redo 1

  3. Go forward in time to latest
    yii migrate mark m210906_125400_latest_one

For Yii 2 it should be (although I haven't tested this set of commands):

  1. Go back in time:
    yiic migrate/mark m210905_112345_to_run_again

  2. Run that one migration again
    yiic migrate/redo 1

  3. Go forward in time to latest
    yii migrate/mark m210906_125400_latest_one

Fisc answered 7/9, 2021 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.