backbone-support 0.11.0

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

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

use super::Seeder;

// ============================================================================
// ISSUE SEEDER
// ============================================================================

/// Seeder for issue
pub struct SeedIssueSeeder;

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

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

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

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

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

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

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

// Add custom seed data methods here