Skip to content

Commit 647bb4c

Browse files
Introduce suspenders:db:migrate task (#1161)
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, the following implementation did not work because Rake recognized that it `db:migrate` was already invoked, so it wasn't invoked a second time. ```ruby task migrate: ["db:migrate", "db:rollback", "db:migrate", "db:test:prepare"] ``` Instead, we needed to `reenable` the task manually. [dotfiles]: https://github.com/thoughtbot/dotfiles/blob/f149484269ef98e2bc80b7daa1988e214ddf8e8b/aliases#L12 [in these comments]: thoughtbot/dotfiles@4882c41#r1933964
1 parent 63fa9cd commit 647bb4c

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-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:db: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:db:migrate
160+
```
161+
153162
## Contributing
154163

155164
See the [CONTRIBUTING] document.

lib/tasks/suspenders.rake

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

0 commit comments

Comments
 (0)