backbone-pos 0.7.0

Point of sale — cashier session, ticket + multi-tender; orchestrates billing (revenue) + payment (settlement), posts no GL directly
Documentation
//! PosDiscount seeder
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Seeds initial PosDiscount data into the database.

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

use super::Seeder;

// ============================================================================
// POSDISCOUNT SEEDER
// ============================================================================

/// Seeder for pos_discount
pub struct SeedPosDiscountSeeder;

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

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

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

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

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

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

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

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