Skip to content

Commit ff191ce

Browse files
Simplify up / down migration example [ci-skip]
Follow-up to rails#47782. These examples merely illustrate the order of execution when using `up` and `down`, so we only need one operation before and after.
1 parent 400d9d4 commit ff191ce

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

guides/source/active_record_migrations.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -758,16 +758,15 @@ class ExampleMigration < ActiveRecord::Migration[7.2]
758758
end
759759
end
760760

761-
add_column :users, :home_page_url, :string
762-
rename_column :users, :email, :email_address
761+
add_column :users, :address, :string
763762
end
764763
end
765764
```
766765

767766
Using `reversible` will ensure that the instructions are executed in the right
768767
order too. If the previous example migration is reverted, the `down` block will
769-
be run after the `home_page_url` column is removed and `email_address` column is renamed and right before the table
770-
`distributors` is dropped.
768+
be run after the `users.address` column is removed and before the `distributors`
769+
table is dropped.
771770

772771
[`reversible`]: https://api.rubyonrails.org/classes/ActiveRecord/Migration.html#method-i-reversible
773772

@@ -800,13 +799,11 @@ class ExampleMigration < ActiveRecord::Migration[7.2]
800799
FROM distributors;
801800
SQL
802801

803-
add_column :users, :home_page_url, :string
804-
rename_column :users, :email, :email_address
802+
add_column :users, :address, :string
805803
end
806804

807805
def down
808-
rename_column :users, :email_address, :email
809-
remove_column :users, :home_page_url
806+
remove_column :users, :address
810807

811808
execute <<-SQL
812809
DROP VIEW distributors_view;

0 commit comments

Comments
 (0)