backbone-inventory 0.9.29

Inventory: stock ledger of record (SLE) + moving-average valuation; emits COGS/asset AccountingPost (Delivery/Receipt -> GL)
Documentation
//! Quant seeder
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Seeds initial Quant data into the database.

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

use super::Seeder;

// ============================================================================
// QUANT SEEDER
// ============================================================================

/// Seeder for quant
pub struct SeedQuantSeeder;

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

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

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

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

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

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

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

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