From a25ddf6c03b691eb2418d64032ce86e4508ed8e7 Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Tue, 20 Feb 2024 07:36:14 -0500 Subject: [PATCH] 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]: https://github.com/thoughtbot/dotfiles/commit/4882c418fd1cb4d052193d4e70a8df316e6cf9c6#r1933964 --- NEWS.md | 1 + README.md | 9 +++++++++ lib/tasks/suspenders.rake | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/NEWS.md b/NEWS.md index b9d879e86..349dbb106 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:migrate` task 20230113.0 (January, 13, 2023) diff --git a/README.md b/README.md index c32f3554b..d274bcd37 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:migrate +``` + ## Contributing See the [CONTRIBUTING] document. diff --git a/lib/tasks/suspenders.rake b/lib/tasks/suspenders.rake index 2a76754b5..5cbae9cf4 100644 --- a/lib/tasks/suspenders.rake +++ b/lib/tasks/suspenders.rake @@ -9,4 +9,15 @@ namespace :suspenders do Rake::Task[:standard].invoke end end + + desc "Ensure a migration is reversible" + 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