backbone-accounting 0.18.0

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

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

use super::Seeder;

// ============================================================================
// PRINTEDCHECK SEEDER
// ============================================================================

/// Seeder for printed_check
pub struct SeedPrintedCheckSeeder;

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

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

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

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

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

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

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

// Add custom seed data methods here