feat: run migrations while starting with monolith

just more user friendly
This commit is contained in:
əlemi 2025-01-22 01:18:40 +01:00
parent 410dca1eef
commit 2e41df9bf3
Signed by: alemi
GPG key ID: A4895B84D311642C

10
main.rs
View file

@ -157,14 +157,19 @@ async fn init(args: Args, config: upub::Config) {
.await.expect("error connecting to db"); .await.expect("error connecting to db");
#[cfg(feature = "migrate")] #[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; use migrations::MigratorTrait;
migrations::Migrator::up(&db, None) migrations::Migrator::up(&db, None)
.await .await
.expect("error applying migrations"); .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(); let (tx_wake, rx_wake) = tokio::sync::mpsc::unbounded_channel();
@ -181,7 +186,6 @@ async fn init(args: Args, config: upub::Config) {
return; return;
} }
// register signal handler only for long-lasting modes, such as server or worker // register signal handler only for long-lasting modes, such as server or worker
let (tx, rx) = tokio::sync::watch::channel(false); let (tx, rx) = tokio::sync::watch::channel(false);
let signals = Signals::new([SIGTERM, SIGINT]).expect("failed registering signal handler"); let signals = Signals::new([SIGTERM, SIGINT]).expect("failed registering signal handler");