backbone-banking 0.7.1

Cash & bank — bank/account master, statement import, reconciliation, and clearing postings (5th GL producer)
Documentation
//! BankAccount seeder
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Seeds initial BankAccount data into the database.

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

use super::Seeder;

// ============================================================================
// BANKACCOUNT SEEDER
// ============================================================================

/// Seeder for bank_account
pub struct SeedBankAccountSeeder;

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

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

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

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

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

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

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

// <<< CUSTOM SEED DATA START >>>
// Add custom seed data methods here
// <<< CUSTOM SEED DATA END >>>