mirror of
https://github.com/jbranchaud/til
synced 2026-01-06 08:38:01 +00:00
Add Migrating Up Down Up as a rails til.
This commit is contained in:
16
rails/migrating-up-down-up.md
Normal file
16
rails/migrating-up-down-up.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# Migrating Up Down Up
|
||||
|
||||
When writing Rails migrations, it is good to define, when possible, what
|
||||
should happen when migrating *up* and what should happen when migrating
|
||||
*down*. You'll then want to check that both the *up* and *down* work. This
|
||||
can be accomplished using the following one-liner:
|
||||
|
||||
```bash
|
||||
$ rake db:migration && rake db:migration:redo
|
||||
```
|
||||
|
||||
The `rake db:migration` does what we would expect applying our new migration
|
||||
and showing us that our *up* works. The `rake db:migrate:redo` first
|
||||
performs a rollback, showing us that our *down* works, and then migrates
|
||||
back up again. We now know that our latest migration works going both
|
||||
directions.
|
||||
Reference in New Issue
Block a user