Skip to content

Commit a25ddf6

Browse files
Introduce suspenders:migrate task
Lifted from our [dotfiles][], this task runs the latest migration, rolls it back, and runs it again in an effort to ensure it's reversible. More context can be found [in these comments][]. Unfortunately, this implementation did not work because Rake recognized that it `db:migrate` was already invoked, so it wasn't invoked a second time. Instead, we needed to `reenable` the task manually. ```ruby task migrate: ["db:migrate", "db:rollback", "db:migrate", "db:test:prepare"] ``` [dotfiles]: https://github.com/thoughtbot/dotfiles/blob/f149484269ef98e2bc80b7daa1988e214ddf8e8b/aliases#L12 [in these comments]: thoughtbot/dotfiles@4882c41#r1933964
1 parent 63fa9cd commit a25ddf6

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Unreleased
1212
* Introduce `suspenders:views` generator
1313
* Introduce `suspenders:setup` generator
1414
* Introduce `suspenders:tasks` generator
15+
* Introduce `suspenders:migrate` task
1516

1617
20230113.0 (January, 13, 2023)
1718

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ Creates local Rake tasks for development
150150
bin/rails dev:prime
151151
```
152152

153+
#### Suspenders Tasks
154+
155+
Custom Suspenders tasks
156+
157+
```
158+
bin/rails suspenders:rake
159+
bin/rails suspenders:migrate
160+
```
161+
153162
## Contributing
154163

155164
See the [CONTRIBUTING] document.

lib/tasks/suspenders.rake

+11
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@ namespace :suspenders do
99
Rake::Task[:standard].invoke
1010
end
1111
end
12+
13+
desc "Ensure a migration is reversible"
14+
task :migrate do
15+
Rake::Task["db:migrate"].invoke
16+
Rake::Task["db:rollback"].invoke
17+
18+
Rake::Task["db:migrate"].reenable
19+
Rake::Task["db:migrate"].invoke
20+
21+
Rake::Task["db:test:prepare"].invoke
22+
end
1223
end

0 commit comments

Comments
 (0)