backbone-banking 0.7.1

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

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

use super::Seeder;

// ============================================================================
// RECONCILEPRESET SEEDER
// ============================================================================

/// Seeder for reconcile_preset
pub struct SeedReconcilePresetSeeder;

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

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

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

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

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

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

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

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