Skip to content

Commit

Permalink
Introduce suspenders:db:migrate task (#1161)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stevepolitodesign committed Feb 20, 2024
1 parent 63fa9cd commit 647bb4c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Unreleased
* Introduce `suspenders:views` generator
* Introduce `suspenders:setup` generator
* Introduce `suspenders:tasks` generator
* Introduce `suspenders:db:migrate` task

20230113.0 (January, 13, 2023)

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ Creates local Rake tasks for development
bin/rails dev:prime
```

#### Suspenders Tasks

Custom Suspenders tasks

```
bin/rails suspenders:rake
bin/rails suspenders:db:migrate
```

## Contributing

See the [CONTRIBUTING] document.
Expand Down
13 changes: 13 additions & 0 deletions lib/tasks/suspenders.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,17 @@ namespace :suspenders do
Rake::Task[:standard].invoke
end
end

desc "Ensure a migration is reversible"
namespace :db do
task :migrate do
Rake::Task["db:migrate"].invoke
Rake::Task["db:rollback"].invoke

Rake::Task["db:migrate"].reenable
Rake::Task["db:migrate"].invoke

Rake::Task["db:test:prepare"].invoke
end
end
end

0 comments on commit 647bb4c

Please sign in to comment.