From 2e41df9bf37b03fa3fdd993655330d642483a0e0 Mon Sep 17 00:00:00 2001 From: alemi <me@alemi.dev> Date: Wed, 22 Jan 2025 01:18:40 +0100 Subject: [PATCH] feat: run migrations while starting with monolith just more user friendly --- main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.rs b/main.rs index c2a217a..11ca05d 100644 --- a/main.rs +++ b/main.rs @@ -157,14 +157,19 @@ async fn init(args: Args, config: upub::Config) { .await.expect("error connecting to db"); #[cfg(feature = "migrate")] - if matches!(args.command, Mode::Migrate) { + if matches!(args.command, Mode::Migrate | Mode::Monolith { bind: _, tasks: _, poll: _ }) { + // note that, if running in monolith mode, we want to apply migrations before starting, as a + // convenience for quickly spinning up new test instances and to prevent new server admins from + // breaking stuff by forgetting to migrate use migrations::MigratorTrait; migrations::Migrator::up(&db, None) .await .expect("error applying migrations"); - return; + if matches!(args.command, Mode::Migrate) { + return; // if migrate, we're done! otherwise keep going + } } let (tx_wake, rx_wake) = tokio::sync::mpsc::unbounded_channel(); @@ -181,7 +186,6 @@ async fn init(args: Args, config: upub::Config) { return; } - // register signal handler only for long-lasting modes, such as server or worker let (tx, rx) = tokio::sync::watch::channel(false); let signals = Signals::new([SIGTERM, SIGINT]).expect("failed registering signal handler");