split some logic out of KeyValueDatabase::load_or_create

This method did _a lot_ of things at the same time. In order to use
`KeyValueDatabase` for the migrate-db command, we need to be able to
open a db without attempting to apply all the migrations and without
spawning a bunch of unrelated background tasks.

The state after this refactor is still not great, but it's enough to do
a migration tool.
This commit is contained in:
Benjamin Lee 2024-09-08 16:31:51 -07:00 committed by Charles Hall
parent 059dfe54e3
commit 279c6472c5
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
3 changed files with 127 additions and 103 deletions

View file

@ -70,9 +70,15 @@ pub(crate) async fn run(args: ServeArgs) -> Result<(), error::ServeCommand> {
.expect("should be able to increase the soft limit to the hard limit");
info!("Loading database");
KeyValueDatabase::load_or_create(config, reload_handles)
.await
let db = KeyValueDatabase::load_or_create(config, reload_handles)
.map_err(Error::DatabaseError)?;
db.apply_migrations().await.map_err(Error::DatabaseError)?;
info!("Starting background tasks");
services().admin.start_handler();
services().sending.start_handler();
KeyValueDatabase::start_cleanup_task();
services().globals.set_emergency_access();
info!("Starting server");
run_server().await?;