backbone-bucket 0.3.0

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! FileShare seeder
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Seeds initial FileShare data into the database.

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

use super::Seeder;

// ============================================================================
// FILESHARE SEEDER
// ============================================================================

/// Seeder for file_share
pub struct SeedFileShareSeeder;

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

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

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

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

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

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

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

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