Skip to main content

backbone_bucket/seeders/
file_comment_seeder.rs

1//! FileComment seeder
2//!
3//! Generated by metaphor-schema. Do not edit manually.
4//!
5//! Seeds initial FileComment data into the database.
6
7use anyhow::Result;
8use async_trait::async_trait;
9use sqlx::PgPool;
10
11use super::Seeder;
12
13// ============================================================================
14// FILECOMMENT SEEDER
15// ============================================================================
16
17/// Seeder for file_comment
18pub struct SeedFileCommentSeeder;
19
20impl SeedFileCommentSeeder {
21    pub fn new() -> Self {
22        Self
23    }
24}
25
26impl Default for SeedFileCommentSeeder {
27    fn default() -> Self {
28        Self::new()
29    }
30}
31
32#[async_trait]
33impl Seeder for SeedFileCommentSeeder {
34    fn name(&self) -> &'static str {
35        "SeedFileCommentSeeder"
36    }
37
38    fn order(&self) -> i32 {
39        13
40    }
41
42    async fn should_run(&self, pool: &PgPool) -> Result<bool> {
43        // Check if bucket.file_comments table has any data
44        let count: (i64,) = sqlx::query_as("SELECT COUNT(*) FROM bucket.file_comments")
45            .fetch_one(pool)
46            .await?;
47        Ok(count.0 == 0)
48    }
49
50    async fn run(&self, pool: &PgPool) -> Result<()> {
51        // Run the SQL seed file
52        let sql = include_str!("../../migrations/seeds/file_comment_seed.sql");
53        sqlx::raw_sql(sql).execute(pool).await?;
54        Ok(())
55    }
56
57    async fn rollback(&self, pool: &PgPool) -> Result<()> {
58        sqlx::query("DELETE FROM bucket.file_comments")
59            .execute(pool)
60            .await?;
61        Ok(())
62    }
63}
64
65// ============================================================================
66// CUSTOM SEED DATA
67// ============================================================================
68
69// Add custom seed data methods here
70