Skip to content

Commit

Permalink
fix: skip running migrate when there is no metadata.json file (Qovery…
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriceclementz authored May 26, 2022
1 parent 5c58951 commit b52e40f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions replibyte/src/migration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::io::{Error, ErrorKind};
use std::str::FromStr;

use log::info;

use crate::datastore::Datastore;
use crate::migration::rename_backups_to_dumps::RenameBackupsToDump;
use crate::migration::update_version_number::UpdateVersionNumber;
Expand Down Expand Up @@ -79,13 +81,21 @@ impl<'a> Migrator<'a> {

/// run all registered migrations when the minimal version is matched.
pub fn migrate(&self) -> Result<(), Error> {
for migration in &self.migrations {
if self.should_run_migration(migration) {
let _ = migration.run(&self.datastore)?;
}
match self.datastore.raw_index_file() {
Ok(_) => {
for migration in &self.migrations {
if self.should_run_migration(migration) {
let _ = migration.run(&self.datastore)?;
}
}
Ok(())
},
Err(err) => {
// raw_index_file returns an error when we don't have a metadata.json file, in this case we don't need to run migrations.
info!("migrate: skip migrate '{}'", err.to_string());
Ok(())
},
}

Ok(())
}

fn should_run_migration(&self, migration: &Box<dyn Migration>) -> bool {
Expand Down

0 comments on commit b52e40f

Please sign in to comment.