Skip to content

Commit

Permalink
Fixing bug with generating new schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mjovanc committed Mar 25, 2024
1 parent cca3f9b commit 6425bcb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions njord_cli/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,25 @@ pub fn read_config() -> Result<TomlConfig, ConfigError> {
///
pub fn get_next_migration_version(migrations_dir: &Path) -> Result<String, std::io::Error> {
let entries = fs::read_dir(migrations_dir)?;
let max_version = entries
let versions: Vec<u64> = entries
.filter_map(|entry| {
entry
.ok()
entry.ok()
.and_then(|e| e.file_name().to_str().map(String::from))
})
.filter(|version| version.len() == 14)
.max();
.filter_map(|version| {
// Split the version string by '_' and take the first part
version.split('_').next().unwrap_or_default().parse().ok()
})
.collect();

let max_version = versions.into_iter().max();

match max_version {
Some(max_version) => {
let next_version: Result<u64, ParseIntError> = max_version.parse();
match next_version {
Ok(n) => Ok(format!("{:014}", n + 1)),
Err(err) => Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, err)),
}
Some(max_value) => {
let next_version = max_value + 1;
Ok(format!("{:014}", next_version))
}
None => Ok("00000000000001".to_string()), // initial version
None => Ok("00000000000001_unknown".to_string()), // initial version
}
}

Expand Down
Empty file.
Empty file.

0 comments on commit 6425bcb

Please sign in to comment.