backbone-accounting 0.18.0

GL, journals, ledger, reconciliation (extracted from bersihir)
Documentation
//! Reconciliation seeder
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Seeds initial Reconciliation data into the database.

use anyhow::Result;
use async_trait::async_trait;
use sqlx::PgPool;

use super::Seeder;

// ============================================================================
// RECONCILIATION SEEDER
// ============================================================================

/// Seeder for reconciliation
pub struct SeedReconciliationSeeder;

impl SeedReconciliationSeeder {
    pub fn new() -> Self {
        Self
    }
}

impl Default for SeedReconciliationSeeder {
    fn default() -> Self {
        Self::new()
    }
}

#[async_trait]
impl Seeder for SeedReconciliationSeeder {
    fn name(&self) -> &'static str {
        "SeedReconciliationSeeder"
    }

    fn order(&self) -> i32 {
        7
    }

    async fn should_run(&self, pool: &PgPool) -> Result<bool> {
        // Check if accounting.reconciliations table has any data
        let count: (i64,) = sqlx::query_as("SELECT COUNT(*) FROM accounting.reconciliations")
            .fetch_one(pool)
            .await?;
        Ok(count.0 == 0)
    }

    async fn run(&self, pool: &PgPool) -> Result<()> {
        // Run the SQL seed file
        let sql = include_str!("../../migrations/seeds/reconciliation_seed.sql");
        sqlx::raw_sql(sql).execute(pool).await?;
        Ok(())
    }

    async fn rollback(&self, pool: &PgPool) -> Result<()> {
        sqlx::query("DELETE FROM accounting.reconciliations")
            .execute(pool)
            .await?;
        Ok(())
    }
}

// ============================================================================
// CUSTOM SEED DATA
// ============================================================================

// Add custom seed data methods here