Useful debug post that only happens once per db

This commit is contained in:
Imbus 2023-10-21 08:58:21 +02:00
parent 985ce53a97
commit 3a007f0093

View file

@ -56,10 +56,19 @@ async fn debug_setup(pool: &SqlitePool) -> Result<(), sqlx::Error> {
db_new_user("user".to_string(), "pass".to_string(), pool).await;
// 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!')",)
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(())
}