diff --git a/server/src/state.rs b/server/src/state.rs index 7d038fd..6264987 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -56,10 +56,19 @@ async fn debug_setup(pool: &SqlitePool) -> Result<(), sqlx::Error> { db_new_user("user".to_string(), "pass".to_string(), pool).await; - // This requires that the user with id 1 exists in the user table - query!("INSERT INTO posts (user_id, content) VALUES (1, 'Hello world!')",) + // Check if the demo post already exists + let posted = query!("SELECT * FROM posts WHERE id = 1",) + .fetch_one(pool) + .await + .ok(); + + // If the demo user already has a post, don't insert another one + if !posted.is_some() { + // This requires that the user with id 1 exists in the user table + query!("INSERT INTO posts (user_id, content) VALUES (1, 'Hello world! The demo username is user and the password is pass.')",) .execute(pool) .await?; + } Ok(()) }