Useful debug post that only happens once per db
This commit is contained in:
parent
985ce53a97
commit
3a007f0093
1 changed files with 11 additions and 2 deletions
|
@ -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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue