MCPcopy Create free account
hub / github.com/chatmail/core / run_migrations

Method run_migrations

src/sql.rs:212–246  ·  view source on GitHub ↗

Updates SQL schema to the latest version.

(&self, context: &Context)

Source from the content-addressed store, hash-verified

210
211 /// Updates SQL schema to the latest version.
212 pub async fn run_migrations(&self, context: &Context) -> Result<()> {
213 // (1) update low-level database structure.
214 // this should be done before updates that use high-level objects that
215 // rely themselves on the low-level structure.
216
217 let recode_avatar = migrations::run(context, self)
218 .await
219 .context("failed to run migrations")?;
220
221 // (2) updates that require high-level objects
222 // the structure is complete now and all objects are usable
223
224 if recode_avatar && let Some(avatar) = context.get_config(Config::Selfavatar).await? {
225 let mut blob = BlobObject::from_path(context, Path::new(&avatar))?;
226 match blob.recode_to_avatar_size(context).await {
227 Ok(()) => {
228 if let Some(path) = blob.to_abs_path().to_str() {
229 context
230 .set_config_internal(Config::Selfavatar, Some(path))
231 .await?;
232 } else {
233 warn!(context, "Setting selfavatar failed: non-UTF-8 filename");
234 }
235 }
236 Err(e) => {
237 warn!(context, "Migrations can't recode avatar, removing. {:#}", e);
238 context
239 .set_config_internal(Config::Selfavatar, None)
240 .await?
241 }
242 }
243 }
244
245 Ok(())
246 }
247
248 /// Opens the provided database and runs any necessary migrations.
249 /// If a database is already open, this will return an error.

Calls 5

recode_to_avatar_sizeMethod · 0.80
to_abs_pathMethod · 0.80
set_config_internalMethod · 0.80
runFunction · 0.50
get_configMethod · 0.45