Files
spacedrive/core/tests/database_migration_test.rs
Jamie Pine ecdcf04066 Refactor logging output to remove emojis and improve consistency
- Updated various print statements across the codebase to remove emoji indicators, ensuring a more uniform logging style.
- Adjusted output messages in CLI, job handling, and event processing to enhance clarity and maintainability.
- Refactored job-related logging to provide clearer status updates without emoji clutter.

Co-authored-by: ijamespine <ijamespine@me.com>
2025-09-18 22:44:10 -07:00

64 lines
1.5 KiB
Rust

//! Test database migration functionality
use sd_core::infra::db::Database;
use tempfile::TempDir;
#[tokio::test]
async fn test_database_creation_and_migration() {
// Create a temporary directory for the test database
let temp_dir = TempDir::new().unwrap();
let db_path = temp_dir.path().join("test.db");
println!("Creating database at: {:?}", db_path);
// Create the database
let db = Database::create(&db_path)
.await
.expect("Failed to create database");
println!("Database created successfully, running migrations...");
// Run migrations with debug info
println!("Running migrations...");
let result = db.migrate().await;
match result {
Ok(()) => {
println!("Migrations completed successfully!");
}
Err(e) => {
println!("❌ Migration failed: {}", e);
panic!("Migration failed: {}", e);
}
}
// Verify the database exists and has tables
assert!(db_path.exists(), "Database file should exist");
// Try to connect to verify it's a valid database
let conn = db.conn();
// Try a simple query to verify the database is working
use sea_orm::{ConnectionTrait, Statement};
let result = conn
.execute(Statement::from_string(
sea_orm::DatabaseBackend::Sqlite,
"SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;".to_string(),
))
.await;
match result {
Ok(result) => {
println!(
"Database query successful, {} rows affected",
result.rows_affected()
);
}
Err(e) => {
println!("❌ Database query failed: {}", e);
panic!("Database query failed: {}", e);
}
}
}