Skip to content

Commit

Permalink
Fix issues with environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
nledford committed Aug 1, 2024
1 parent 35e509b commit 58c6fb7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hitomi"
version = "0.8.0"
version = "0.8.1"
description = "A CLI application that builds and updates playlists on a Plex server using json-based profiles."
authors = ["Nathaniel Ledford <nate@nateledford.com>"]
homepage = "https://github.com/nledford/hitomi"
Expand Down
9 changes: 7 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ docker-build:

# Build and run a docker image
[group('docker')]
docker-run: docker-build
docker run -e TZ="America/New_York" -e -it -v "./data:/data" -v --rm --name hitomi nledford/hitomi:latest run
docker-run:
#!/usr/bin/env bash
docker run\
-e TZ='America/New_York'\
-e DATABASE_URL='sqlite:/data/hitomi.db'\
-v "./data:/data"\
--rm -it --name hitomi nledford/hitomi:latest run
# Run clippy. Fails if clippy finds issues.
[group('rust')]
Expand Down
8 changes: 7 additions & 1 deletion src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn get_pool() -> Result<&'static SqlitePool> {
}

pub async fn initialize_pool(database_url: Option<&str>) -> Result<()> {
let database_url = if let Ok(database_url) = env::var("DATABAE_URL") {
let database_url = if let Ok(database_url) = env::var("DATABASE_URL") {
database_url
} else if let Some(database_url) = database_url {
database_url.to_string()
Expand All @@ -31,6 +31,12 @@ pub async fn initialize_pool(database_url: Option<&str>) -> Result<()> {
String::from("sqlite:./data/hitomi.db")
};

let database_url = if database_url.contains("sqlite:") {
database_url
} else {
format!("sqlite:{database_url}")
};

let options =
SqliteConnectOptions::from_str(&database_url)?.journal_mode(SqliteJournalMode::Wal);

Expand Down

0 comments on commit 58c6fb7

Please sign in to comment.