61 lines
2.2 KiB
Rust
61 lines
2.2 KiB
Rust
//! Database seeder binary.
|
|
//!
|
|
//! Initialises the store directory structure and creates default
|
|
//! configuration files plus a seed session for development/testing.
|
|
//! Invoked as `cargo run --bin seed`.
|
|
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
let store = zesdex_domain::core::Store::new();
|
|
store.ensure_dirs()?;
|
|
|
|
// Create default settings if not present
|
|
let settings_path = store.base_dir.join("settings.json");
|
|
if !settings_path.exists() {
|
|
let settings = zesdex_domain::cms::Settings::default();
|
|
let content = serde_json::to_string_pretty(&settings)?;
|
|
let tmp = store.base_dir.join("settings.json.tmp");
|
|
std::fs::write(&tmp, content)?;
|
|
let f = std::fs::File::open(&tmp)?;
|
|
f.sync_all()?;
|
|
std::fs::rename(&tmp, settings_path)?;
|
|
tracing::info!("Default settings created");
|
|
} else {
|
|
tracing::info!("Settings already exist, skipping");
|
|
}
|
|
|
|
// Create default app config if not present
|
|
let config_path = store.base_dir.join("app_config.json");
|
|
if !config_path.exists() {
|
|
let config = zesdex_domain::cms::AppConfig::default();
|
|
let content = serde_json::to_string_pretty(&config)?;
|
|
let tmp = store.base_dir.join("app_config.json.tmp");
|
|
std::fs::write(&tmp, content)?;
|
|
let f = std::fs::File::open(&tmp)?;
|
|
f.sync_all()?;
|
|
std::fs::rename(&tmp, config_path)?;
|
|
tracing::info!("Default app_config created");
|
|
} else {
|
|
tracing::info!("App config already exists, skipping");
|
|
}
|
|
|
|
// Create data directories
|
|
std::fs::create_dir_all(&store.memory_dir)?;
|
|
std::fs::create_dir_all(&store.session_images_dir)?;
|
|
tracing::info!("All store directories verified");
|
|
|
|
// Create a seed session
|
|
let session_id = uuid::Uuid::new_v4().to_string();
|
|
let session = zesdex_domain::auth::Session::new(
|
|
session_id.clone(),
|
|
"Seed Session".to_string(),
|
|
);
|
|
// Persist via the session repository
|
|
use zesdex_domain::SessionRepository;
|
|
let repo = zesdex_infrastructure::persistence::iam::session_repo::FileSystemSessionRepository::new();
|
|
repo.save_session(&store.base_dir, &session)?;
|
|
tracing::info!("Seed session created: id={session_id}");
|
|
|
|
Ok(())
|
|
}
|