Debug builds now provides dummy posts

This commit is contained in:
Imbus 2023-11-15 11:32:57 +01:00
parent 686afb979c
commit 6b81763259
4 changed files with 36 additions and 0 deletions

View file

@ -61,6 +61,7 @@ impl ServerState {
// Mostly useful for debugging new posts, as we need to satisfy foreign key constraints.
#[cfg(debug_assertions)]
async fn debug_setup(pool: &PgPool) -> Result<(), sqlx::Error> {
use lipsum::lipsum;
use sqlx::query;
use crate::db::db_new_user;
@ -79,6 +80,15 @@ async fn debug_setup(pool: &PgPool) -> Result<(), sqlx::Error> {
query!("INSERT INTO posts (user_id, content) VALUES (1, 'Hello world! The demo username is user and the password is pass.')",)
.execute(pool)
.await?;
for _ in 0..10 {
query!(
"INSERT INTO posts (user_id, content) VALUES (1, $1)",
lipsum(50)
)
.execute(pool)
.await?;
}
}
Ok(())