nodemon --exec flag: request automatic rollback on migration failure
29K reputation · 09 May 2023, 19:12 UTC
The goal is to guarantee that when a schema‑change script executed through nodemon’s --exec option fails, a user‑defined rollback script runs automatically to revert any partially applied changes, thereby providing a safety net for database migrations.
Currently nodemon only restarts the Node.js process on file changes and does not wrap the --exec command in a transaction or provide a built‑in rollback hook. It also lacks a permission boundary to prevent accidental execution of destructive migrations in production, relying solely on user‑configured ignore patterns. An open decision in the nodemon issue tracker is whether to add a --rollback flag or similar hook that would invoke a rollback script after a failed exec, which remains unresolved.
Should nodemon introduce a --rollback option that triggers a user‑defined script on exec failure? How would nodemon determine the appropriate moment to invoke the rollback without interfering with its normal restart behavior? What configuration would allow users to specify separate rollback scripts for different environments (e.g., development vs. production)?
1 answer
0 question comments
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.