File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket.
99
1010For a steady stream of TILs, [ sign up for my newsletter] ( https://tinyletter.com/jbranchaud ) .
1111
12- _ 902 TILs and counting..._
12+ _ 903 TILs and counting..._
1313
1414---
1515
@@ -551,6 +551,7 @@ _902 TILs and counting..._
551551- [ Log SQL Queries Executed By ActiveRecord] ( rails/log-sql-queries-executed-by-activerecord.md )
552552- [ Mark A Migration As Irreversible] ( rails/mark-a-migration-as-irreversible.md )
553553- [ Make ActionMailer Synchronous In Test] ( rails/make-action-mailer-synchronous-in-test.md )
554+ - [ Manually Run A Migration From Rails Console] ( rails/manually-run-a-migration-from-rails-console.md )
554555- [ Mark For Destruction] ( rails/mark-for-destruction.md )
555556- [ Merge A Scope Into An ActiveRecord Query] ( rails/merge-a-scope-into-an-activerecord-query.md )
556557- [ Migrating Up Down Up] ( rails/migrating-up-down-up.md )
Original file line number Diff line number Diff line change 1+ # Manually Run A Migrations From Rails Console
2+
3+ A migration can be manually run from the rails console. In 99% of cases you are
4+ going to be better off using the migration CLI that Rails provides (e.g. `rails
5+ db: migrate ` , ` rails db: rollback `, etc.).
6+
7+ If you are in a hyper-specific scenario where you need to run the ` up ` or the
8+ ` down ` of a migration without the migration-table check, then you'll want to
9+ consider this approach.
10+
11+ First, connect to the rails console: ` rails c ` . Then require your migration
12+ file.
13+
14+ ``` ruby
15+ > require " ./db/migration/20200220181733_some_migration.rb"
16+ # => true
17+ ```
18+
19+ You'll now have access to the ` SomeMigration ` constant. Create an instance of this and then run either the ` up ` -side of the migration:
20+
21+ ``` ruby
22+ > SomeMigration .new .up
23+ # => ... # a bunch of migration output
24+ ```
25+
26+ or the ` down ` -side of it:
27+
28+ ``` ruby
29+ > SomeMigration .new .down
30+ # => ... # a bunch of migration output
31+ ```
32+
33+ [ source] ( https://stackoverflow.com/a/754316/535590 )
You can’t perform that action at this time.
0 commit comments