docs: tambah doc comment, logging, dan inline comments di semua 255 file

Meliputi:
- File-level //! doc comment: tujuan file, alur kerja, komponen utama
- Function-level /// doc comment: apa, parameter, return, flow, edge cases
- Struct/enum/trait /// doc comment: peran, field docs
- Tracing logging (tracing::info!/debug!/trace!/warn!/error!) di setiap fungsi
- Inline comments untuk variable dan branching logic penting
- Seluruh 8 crates di workspace: zesdex-backend, zesdex-cms, zesdex-entities,
  zesdex-iam, zesdex-infra, zesdex-ipc, zesdex-middleware, zesdex-utils
- Build: 0 errors, 242/242 tests passed
This commit is contained in:
asepharyana
2026-07-19 17:05:47 +07:00
parent 6680795ce7
commit 5aaedbf787
255 changed files with 5666 additions and 743 deletions
+49 -4
View File
@@ -1,12 +1,43 @@
//! Database migration: creates/upgrades SQLite schemas for all sessions.
//! Database migration binary for zesdex-backend.
//!
//! Scans all session directories under the store path and initializes or
//! upgrades the SQLite schema (`messages.sqlite`) for each one. This is
//! a standalone CLI tool invoked as `cargo run --bin migrate`.
//!
//! ## Workflow
//! 1. Resolve the base store directory via `Store::new()`
//! 2. Iterate over each subdirectory under `sessions/`
//! 3. For each session directory, call `migrate_session_msglog()` to
//! create/upgrade the `messages.sqlite` schema
//! 4. Report count of succeeded and failed migrations
//! 5. Exit with error if any session failed
//!
//! ## Schema
//! - `messages` table — stores conversation message rows
//! - `archives` table — stores session archive metadata
//! - `blobs` table — stores binary blob data per session
//! - Indexes on `session_id`, `created_at`, and `role` columns
//!
//! ## Versioning
//! SQLite `PRAGMA user_version` tracks schema version for incremental upgrades.
use std::path::Path;
use tracing;
/// Entry point: migrate all session databases.
///
/// Flow: load store → iterate sessions → migrate each → summarise.
///
/// Returns an error if any session migration failed.
fn main() -> anyhow::Result<()> {
tracing::info!("starting database migration");
let store = zesdex_entities::domain::common::store::Store::new();
// Find all session directories
// Resolve the sessions directory under the store base path
let sessions_dir = store.base_dir.join("sessions");
if !sessions_dir.exists() {
tracing::info!("no sessions directory found at {:?}", sessions_dir);
eprintln!("No sessions directory found, nothing to migrate");
return Ok(());
}
@@ -14,25 +45,29 @@ fn main() -> anyhow::Result<()> {
let mut migrated = 0u32;
let mut failed = 0u32;
// Iterate over all session subdirectories
for entry in std::fs::read_dir(&sessions_dir)? {
let entry = entry?;
let path = entry.path();
if !path.is_dir() {
continue;
continue; // skip non-directory entries
}
match migrate_session_msglog(&path) {
Ok(_) => {
migrated += 1;
tracing::info!("migrated session: {:?}", path.file_name());
eprintln!("Migrated session: {:?}", path.file_name());
}
Err(e) => {
failed += 1;
tracing::error!("failed to migrate session {:?}: {e}", path.file_name());
eprintln!("Failed to migrate session {:?}: {e}", path.file_name());
}
}
}
tracing::info!("migration complete: {migrated} succeeded, {failed} failed");
eprintln!("Migration complete: {migrated} succeeded, {failed} failed");
if failed > 0 {
anyhow::bail!("{failed} session(s) failed to migrate");
@@ -40,8 +75,18 @@ fn main() -> anyhow::Result<()> {
Ok(())
}
/// Open a session's `messages.sqlite` and initialize its schema.
/// Open (or create) a session's `messages.sqlite` and ensure its schema is current.
///
/// Flow: resolve path → open/ create DB → set PRAGMAs → create tables → upgrade version.
///
/// ## Parameters
/// - `session_dir`: path to the individual session directory
///
/// ## Returns
/// - `Ok(())` on success
/// - `Err` if file I/O or SQLite operations fail
fn migrate_session_msglog(session_dir: &Path) -> anyhow::Result<()> {
tracing::debug!("migrating session at {:?}", session_dir);
let msglog_path = session_dir.join("messages.sqlite");
if let Some(parent) = msglog_path.parent() {
+24 -2
View File
@@ -1,6 +1,28 @@
//! Database seeder: initializes store directories, creates default settings
//! and app_config, and populates a default session for development.
//! Database seeder binary for zesdex-backend.
//!
//! Standalone CLI tool invoked as `cargo run --bin seed` to initialise
//! the store directory structure and create default configuration files
//! plus a seed session for development and testing.
//!
//! ## Workflow
//! 1. Create the base store directory and all subdirectories
//! 2. Write default `settings.json` if absent (atomic write via temp file + rename)
//! 3. Write default `app_config.json` if absent (same atomic pattern)
//! 4. Create standard subdirectories: `memories`, `scratch`, `session-images`, `downloads`
//! 5. Create a single seed `Session` with a random UUID
//!
//! ## Safety
//! All file writes use an atomic temp-file + rename pattern to prevent
//! partial writes from corrupting configuration files during crashes.
use tracing;
/// Entry point: initialise the store and create seed data.
///
/// Flow: init store dirs → write default settings → write default config →
/// create subdirs → create seed session.
///
/// This is idempotent: if settings or config already exist they are skipped.
fn main() -> anyhow::Result<()> {
let store = zesdex_entities::domain::common::store::Store::new();
store.ensure_dirs()?;