Create sqlite db if not exist, constrain debug deps to debug builds

This commit is contained in:
Imbus 2023-11-04 21:53:55 +01:00
parent d92a1cd617
commit b3124948c4
2 changed files with 9 additions and 2 deletions

View file

@ -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

View file

@ -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)]