backbone-accounting 0.18.0

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

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

use super::Seeder;

// ============================================================================
// FINANCIALSTATEMENT SEEDER
// ============================================================================

/// Seeder for financial_statement
pub struct SeedFinancialStatementSeeder;

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

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

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

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

    async fn should_run(&self, pool: &PgPool) -> Result<bool> {
        // Check if accounting.financial_statements table has any data
        let count: (i64,) = sqlx::query_as("SELECT COUNT(*) FROM accounting.financial_statements")
            .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/financial_statement_seed.sql");
        sqlx::raw_sql(sql).execute(pool).await?;
        Ok(())
    }

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

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

// Add custom seed data methods here