Skip to content

Commit

Permalink
Ensure Database Folder is Created in Docker (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillKirkmanM committed Sep 11, 2024
2 parents 47dab26 + 8de10a2 commit bc64486
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions crates/backend/src/utils/database/database.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fs;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;

Expand All @@ -12,6 +12,8 @@ use dotenvy::dotenv;
use diesel::sqlite::SqliteConnection;
use std::error::Error;

use crate::utils::config::is_docker;

#[derive(Debug)]
pub struct ConnectionOptions {
pub enable_wal: bool,
Expand Down Expand Up @@ -89,18 +91,30 @@ pub fn migrations_ran() -> bool {
}

pub fn get_database_path() -> PathBuf {
let mut path = dirs::data_local_dir().unwrap_or_else(|| PathBuf::from("."));
path.push("ParsonLabs");
path.push("Music");
path.push("Database");
if let Err(e) = fs::create_dir_all(&path) {
eprintln!("Failed to create directories: {}", e);
let path = if is_docker() {
Path::new("/ParsonLabsMusic/Database").to_path_buf()
} else {
let mut path = dirs::data_local_dir().unwrap_or_else(|| PathBuf::from("."));
path.push("ParsonLabs");
path.push("Music");
path.push("Database");
path
};

if let Some(parent) = path.parent() {
if let Err(e) = fs::create_dir_all(parent) {
eprintln!("Failed to create directories: {}", e);
}
}
path.push("music.db");
if !path.exists() {
if let Err(e) = fs::File::create(&path) {

let mut db_path = path.clone();
db_path.push("music.db");

if !db_path.exists() {
if let Err(e) = fs::File::create(&db_path) {
eprintln!("Failed to create database file: {}", e);
}
}
path

db_path
}

0 comments on commit bc64486

Please sign in to comment.