backbone-integrations 0.6.0

Integration registry: connectors, integration accounts and an idempotent inbound event lane, with one OAuth flow (HMAC-bound state, PKCE)
Documentation
//! Example seeder
//!
//! Generated by backbone-schema. Do not edit manually.
//!
//! Seeds initial Example data into the database.

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

use super::Seeder;

/// Seeder for the examples table.
pub struct SeedExampleSeeder;

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

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

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

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

    async fn should_run(&self, pool: &PgPool) -> Result<bool> {
        let count: (i64,) = sqlx::query_as("SELECT COUNT(*) FROM examples")
            .fetch_one(pool)
            .await?;
        Ok(count.0 == 0)
    }

    async fn run(&self, pool: &PgPool) -> Result<()> {
        sqlx::query(
            "INSERT INTO examples (name, description, status) VALUES \
                ('First Example', 'Seeded reference row', 'active'), \
                ('Second Example', NULL, 'inactive')",
        )
        .execute(pool)
        .await?;
        Ok(())
    }

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

// -- <<< CUSTOM SEED DATA >>>