SQLite DB Docker fixes
This commit is contained in:
+7
-3
@@ -1,8 +1,12 @@
|
|||||||
services:
|
services:
|
||||||
typstdrive:
|
typstdrive:
|
||||||
build: .
|
build: .
|
||||||
|
container_name: typstdrive
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3285:3000"
|
||||||
|
environment:
|
||||||
|
# This ensures the database is saved to your mounted volume
|
||||||
|
- DATABASE_URL=sqlite:/app/data/typstdrive.db?mode=rwc
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/app/data
|
- /media/blob/TeaNet/TypstDrive:/app/data
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
+14
-1
@@ -2,9 +2,22 @@ use sqlx::sqlite::SqlitePoolOptions;
|
|||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
|
|
||||||
pub async fn init_db() -> Pool<Sqlite> {
|
pub async fn init_db() -> Pool<Sqlite> {
|
||||||
|
let db_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite:typstdrive.db?mode=rwc".to_string());
|
||||||
|
|
||||||
|
// Ensure parent directory exists if there is one
|
||||||
|
if let Some(path) = db_url.strip_prefix("sqlite:") {
|
||||||
|
if let Some(path) = path.split('?').next() {
|
||||||
|
if let Some(parent) = std::path::Path::new(path).parent() {
|
||||||
|
if !parent.as_os_str().is_empty() {
|
||||||
|
let _ = std::fs::create_dir_all(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let pool = SqlitePoolOptions::new()
|
let pool = SqlitePoolOptions::new()
|
||||||
.max_connections(5)
|
.max_connections(5)
|
||||||
.connect("sqlite:typstdrive.db?mode=rwc")
|
.connect(&db_url)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create pool.");
|
.expect("Failed to create pool.");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user