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
2
justfile
2
justfile
|
@ -32,7 +32,7 @@ build-container-release:
|
|||
|
||||
# Builds a release container and runs it
|
||||
start-release: build-container-release remove-podman-containers
|
||||
{{runtime}} run -d -p 8080:8080 --name frostbyte fb-server
|
||||
{{runtime}} run -d -e DATABASE_URL=sqlite:release.db -p 8080:8080 --name frostbyte fb-server
|
||||
|
||||
init-sqlx:
|
||||
echo "DATABASE_URL=sqlite:debug.db" > server/.env
|
||||
|
|
|
@ -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…
Reference in a new issue