refactor(tests): reformat code and update dependency management
- Reorganized import statements in adapter tests for better readability - Replaced or_insert_with(Vec::new) with or_default() in test closures - Updated Cargo.lock with new dependency versions and checksums - Added TLS features to tonic dependency configuration - Included sqlx, chrono, and uuid dependencies with specific features - Added jsonwebtoken and arc-swap as project dependencies - Reformatted assertion statements to comply with line length limits - Adjusted base64 import order in engine codec module - Updated protobuf include statement formatting
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
//! SQL migration runner.
|
||||
//!
|
||||
//! Reads migration files from the `migrate/` directory and applies them
|
||||
//! in lexicographic order using sqlx's built-in migration infrastructure.
|
||||
|
||||
use sqlx::PgPool;
|
||||
use sqlx::migrate::Migrator;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::{ImksError, ImksResult};
|
||||
|
||||
/// Run all pending SQL migrations from the `migrate/` directory.
|
||||
///
|
||||
/// Migrations are applied in filename order (e.g. `001_…sql` before `002_…sql`).
|
||||
/// sqlx tracks applied migrations in a `_sqlx_migrations` table so that
|
||||
/// only new migrations are executed on subsequent runs.
|
||||
pub async fn run_migrations(pool: &PgPool) -> ImksResult<()> {
|
||||
let migrations_dir = Path::new("migrate");
|
||||
|
||||
if !migrations_dir.exists() {
|
||||
tracing::warn!("No migrate/ directory found — skipping migrations");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let migrator = Migrator::new(migrations_dir)
|
||||
.await
|
||||
.map_err(|e| ImksError::Internal(format!("Failed to load migrations: {e}")))?;
|
||||
|
||||
migrator
|
||||
.run(pool)
|
||||
.await
|
||||
.map_err(|e| ImksError::Internal(format!("Migration failed: {e}")))?;
|
||||
|
||||
tracing::info!("Database migrations completed");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user