Skip to content

Commit

Permalink
feat: handle forward migration errors as non-fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtread committed Apr 27, 2024
1 parent 33606c2 commit 7eb2f41
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7eb2f41

Please sign in to comment.