backbone-support 0.11.0

Customer support: issues tracked against service level agreements, and warranty claims
Documentation
//! WarrantyClaim seeder
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Seeds initial WarrantyClaim data into the database.

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

use super::Seeder;

// ============================================================================
// WARRANTYCLAIM SEEDER
// ============================================================================

/// Seeder for warranty_claim
pub struct SeedWarrantyClaimSeeder;

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

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

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

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

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

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

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

// Add custom seed data methods here