Create sqlite db if not exist, constrain debug deps to debug builds
This commit is contained in:
parent
d92a1cd617
commit
b3124948c4
2 changed files with 9 additions and 2 deletions
|
@ -4,9 +4,9 @@ use std::sync::Mutex;
|
|||
|
||||
use log::error;
|
||||
use log::info;
|
||||
use sqlx::migrate::MigrateDatabase;
|
||||
use sqlx::Pool;
|
||||
use sqlx::Sqlite;
|
||||
use sqlx::SqlitePool;
|
||||
use sqlx::{self, sqlite};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -34,6 +34,10 @@ impl ServerState {
|
|||
let db_url = dotenvy::var("DATABASE_URL").unwrap_or(":memory:".to_string());
|
||||
info!("Using db_url: {}", &db_url);
|
||||
|
||||
if !sqlx::Sqlite::database_exists(&db_url).await.unwrap() {
|
||||
sqlx::Sqlite::create_database(&db_url).await.unwrap();
|
||||
}
|
||||
|
||||
let pool = sqlite::SqlitePoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect(&db_url)
|
||||
|
@ -55,6 +59,9 @@ impl ServerState {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
// Inserts a bunch of dummy data into the database
|
||||
// Mostly useful for debugging new posts, as we need to satisfy foreign key constraints.
|
||||
#[cfg(debug_assertions)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue