factor server_name change check into a reusable fn

This commit is contained in:
Charles Hall 2024-09-24 19:46:21 -07:00
parent c2c6083277
commit 1fd20cdeba
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
3 changed files with 42 additions and 9 deletions

View file

@ -84,15 +84,7 @@ pub(crate) async fn run(args: ServeArgs) -> Result<(), error::ServeCommand> {
.map_err(Error::InitializeServices)?,
)));
// Matrix resource ownership is based on the server name; changing it
// requires recreating the database from scratch. This check needs to be
// done before background tasks are started to avoid data races.
if services().users.count().map(|x| x > 0).map_err(Error::NonZeroUsers)? {
let admin_bot = services().globals.admin_bot_user_id.as_ref();
if !services().users.exists(admin_bot).map_err(Error::AdminBotExists)? {
return Err(Error::Renamed);
}
}
services().globals.err_if_server_name_changed()?;
db.apply_migrations().await.map_err(Error::DatabaseError)?;