25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(app): support portable data directory
t8y27c226ce68483
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 411ace2115..08c0c3fbb4 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -157,6 +157,7 @@ jobs:Copy-Item $exePath (Join-Path $portableDir "DBX.exe") -ForceCopy-Item "LICENSE" (Join-Path $portableDir "LICENSE") -ForceCopy-Item "README.md" (Join-Path $portableDir "README.md") -Force+ Set-Content -Path (Join-Path $portableDir "portable.dbx") -Value "" -NoNewlineCompress-Archive -Path (Join-Path $portableDir "*") -DestinationPath $zipName -Forcegh release upload "${env:GITHUB_REF_NAME}" $zipName --repo "${env:GITHUB_REPOSITORY}" --clobberdiff --git a/src-tauri/src/data_dir.rs b/src-tauri/src/data_dir.rsnew file mode 100644index 0000000000..80a1628164--- /dev/null+++ b/src-tauri/src/data_dir.rs@@ -0,0 +1,58 @@+use std::path::PathBuf;++#[cfg(target_os = "windows")]+const PORTABLE_MARKER: &str = "portable.dbx";++pub fn resolve_data_dir(default_app_data_dir: PathBuf) -> PathBuf {+ if let Some(env_dir) = std::env::var_os("DBX_DATA_DIR").filter(|value| !value.is_empty()) {+ return PathBuf::from(env_dir);+ }++ #[cfg(target_os = "windows")]+ if let Some(exe_dir) = current_exe_dir() {+ if exe_dir.join(PORTABLE_MARKER).is_file() {+ return exe_dir.join("data");+ }+ }++ default_app_data_dir+}++#[cfg(target_os = "windows")]+fn current_exe_dir() -> Option<PathBuf> {+ std::env::current_exe().ok().and_then(|path| path.parent().map(std::path::Path::to_path_buf))+}++#[cfg(test)]+fn resolve_data_dir_from_inputs(+ default_app_data_dir: PathBuf,+ exe_dir: Option<PathBuf>,+ portable_marker_exists: bool,+ env_data_dir: Option<PathBuf>,+) -> PathBuf {+ if let Some(env_dir) = env_data_dir {+ return env_dir;+ }++ match (exe_dir, portable_marker_exists) {+ (Some(dir), true) => dir.join("data"),+ _ => default_app_data_dir,+ }+}++#[cfg(test)]+mod tests {+ use std::path::PathBuf;++ use super::resolve_data_dir_from_inputs;++ #[test]+ fn uses_portable_data_dir_when_marker_exists() {+ let default_dir = PathBuf::from(r"C:\Users\Administrator\AppData\Roaming\com.dbx.app");+ let exe_dir = PathBuf::from(r"D:\Apps\DBX");++ let data_dir = resolve_data_dir_from_inputs(default_dir, Some(exe_dir.clone()), true, None);++ assert_eq!(data_dir, exe_dir.join("data"));+ }+}diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex 5eb29ba333..b58440dacf 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -1,4 +1,5 @@mod commands;+mod data_dir;mod db;mod models;@@ -29,8 +30,9 @@ pub fn run() {app.handle().plugin(tauri_plugin_log::Builder::default().level(log::LevelFilter::Info).build())?;}- let data_dir =+ let default_data_dir =app.path().app_data_dir().map_err(|e| e.to_string()).expect("Failed to resolve app data dir");+ let data_dir = data_dir::resolve_data_dir(default_data_dir);std::fs::create_dir_all(&data_dir).expect("Failed to create data dir");let db_path = data_dir.join("dbx.db");