feat(yedek): JSON tam hane yedeği backend (önizleme, geri yükleme, geri dönüş noktaları)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 20:49:13 +03:00
parent 6e1000afd2
commit 0d70576df7
20 changed files with 1768 additions and 2 deletions
+4
View File
@@ -89,6 +89,10 @@ fn definitions() -> Vec<(&'static str, Vec<IndexModel>)> {
col::IMPORT_RULES,
vec![idx(doc! { "household_id": 1, "pattern": 1 })],
),
(
col::RESTORE_POINTS,
vec![idx(doc! { "household_id": 1, "created_at": -1 })],
),
(
col::EXCHANGE_RATES,
vec![idx(doc! { "code": 1, "household_id": 1, "rate_date": -1 })],
+23
View File
@@ -35,8 +35,18 @@ const MIGRATIONS: &[Migration] = &[
name: "default_assets",
run: |db| Box::pin(m002_default_assets(db)),
},
Migration {
version: 3,
name: "restore_points",
run: |db| Box::pin(m003_restore_points(db)),
},
];
/// En son şema sürümü (JSON yedeğine yazılır; daha yeni yedek reddedilir).
pub fn latest_version() -> i32 {
MIGRATIONS.last().map_or(0, |m| m.version)
}
/// Uygulanmamış migration'ları sırayla çalıştırır.
pub async fn run(db: &Database) -> Result<()> {
let coll = db.collection::<Document>(col::SCHEMA_MIGRATIONS);
@@ -103,6 +113,19 @@ async fn m002_default_assets(db: &Database) -> Result<()> {
Ok(())
}
/// v3: geri dönüş noktaları koleksiyonu (transaction içinde ilk yazımdan önce var olmalı).
async fn m003_restore_points(db: &Database) -> Result<()> {
if !db
.list_collection_names()
.await?
.iter()
.any(|n| n == col::RESTORE_POINTS)
{
db.create_collection(col::RESTORE_POINTS).await?;
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
+2
View File
@@ -73,6 +73,8 @@ pub mod col {
/// Ekstre içe aktarmada öğrenilen açıklama → tür/kategori kuralları
pub const IMPORT_RULES: &str = "import_rules";
pub const SCHEMA_MIGRATIONS: &str = "schema_migrations";
/// JSON geri yüklemeden önce alınan, sıkıştırılmış hane kopyaları ("geri al")
pub const RESTORE_POINTS: &str = "restore_points";
/// Hane verisi taşıyan koleksiyonlar (`household_id` alanı var).
pub const HOUSEHOLD_SCOPED: &[&str] = &[