From 7eb2f418e02e6ede08fe478998b11ab7fe5954a2 Mon Sep 17 00:00:00 2001 From: Jacobtread Date: Sat, 27 Apr 2024 14:16:00 +1200 Subject: [PATCH] feat: handle forward migration errors as non-fatal --- src/database/mod.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/database/mod.rs b/src/database/mod.rs index ea0f1ae..583ab18 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -1,4 +1,4 @@ -use log::{error, info}; +use log::{error, info, warn}; use migration::{Migrator, MigratorTrait}; use sea_orm::Database as SeaDatabase; use std::{ @@ -64,9 +64,24 @@ async fn connect_database() -> DatabaseConnection { .expect("Unable to create database connection"); // Run migrations - Migrator::up(&connection, None) - .await - .expect("Unable to run database migrations"); + if let Err(err) = Migrator::up(&connection, None).await { + if let DbErr::Custom(custom_err) = err { + if custom_err + .contains("is missing, this migration has been applied but its file is missing") + { + // Forward migrations are not always a failure, so its just a warning + warn!( + "It looks like your app.db has been used with a newer version \ + of Pocket Relay, you may encounter unexpected issues or bugs its \ + recommended that you backup your database before trying a new version: {}", + custom_err + ) + } + } else { + // Other errors should be considered fatal + panic!("Failed to run database migrations: {}", err); + } + } connection }