Skip to content

Commit

Permalink
chore(core): add more logs to the remaining branch in db init
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Oct 29, 2024
1 parent f09fd34 commit 309c668
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/nx/src/native/db/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ pub(super) fn initialize_db(nx_version: String, db_path: &Path) -> anyhow::Resul
create_metadata_table(&c, &nx_version)?;
c
}
_ => {
check @ _ => {
trace!("Incompatible database because: {:?}", check);
trace!("Disconnecting from existing incompatible database");
c.close().map_err(|(_, error)| anyhow::Error::from(error))?;
trace!("Removing existing incompatible database");
Expand Down Expand Up @@ -134,6 +135,8 @@ fn configure_database(connection: &NxDbConnection) -> anyhow::Result<()> {
#[cfg(test)]
mod tests {

use crate::native::logger::enable_logger;

use super::*;

#[test]
Expand Down Expand Up @@ -178,22 +181,23 @@ mod tests {

#[test]
fn initialize_db_recreates_incompatible_db() -> anyhow::Result<()> {
enable_logger();
let temp_dir = tempfile::tempdir()?;
let db_path = temp_dir.path().join("test.db");
//
// Create initial db
let _ = initialize_db("1.0.0".to_string(), &db_path)?;

// Try to initialize with different version
let conn = initialize_db("2.0.0".to_string(), &db_path)?;
let conn = initialize_db("0.0.0-pr-28667-e5533b1".to_string(), &db_path)?;

let version: Option<String> = conn.query_row(
"SELECT value FROM metadata WHERE key='NX_VERSION'",
[],
|row| row.get(0),
)?;

assert_eq!(version.unwrap(), "2.0.0");
assert_eq!(version.unwrap(), "0.0.0-pr-28667-e5533b1");
Ok(())
}
}

0 comments on commit 309c668

Please sign in to comment.