From 647bb4cf0eacfdb91ca4f62419e06bb47c9db682 Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Tue, 20 Feb 2024 16:19:45 -0500 Subject: [PATCH] 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]: https://github.com/thoughtbot/dotfiles/commit/4882c418fd1cb4d052193d4e70a8df316e6cf9c6#r1933964 --- NEWS.md | 1 + README.md | 9 +++++++++ lib/tasks/suspenders.rake | 13 +++++++++++++ 3 files changed, 23 insertions(+) diff --git a/NEWS.md b/NEWS.md index b9d879e86..7f21e8fa9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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) diff --git a/README.md b/README.md index c32f3554b..820ccdec1 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/tasks/suspenders.rake b/lib/tasks/suspenders.rake index 2a76754b5..9b62842ad 100644 --- a/lib/tasks/suspenders.rake +++ b/lib/tasks/suspenders.rake @@ -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