mirror of
https://github.com/patdelphi/suanming.git
synced 2026-02-27 21:23:12 +08:00
fix: 修复Koyeb Volume挂载路径问题
- 根据Koyeb实际挂载信息(/workspace/data)调整数据库路径配置 - 添加Koyeb环境检测逻辑,优先使用/workspace/data路径 - 更新.koyeb/koyeb.yaml中的mount_path和DB_PATH配置 - 增强日志输出,显示Koyeb环境状态和工作目录 - 解决数据库持久化路径不匹配导致的数据丢失问题 - 确保Volume正确挂载到/workspace/data目录
This commit is contained in:
@@ -18,7 +18,7 @@ services:
|
|||||||
- key: PORT
|
- key: PORT
|
||||||
value: "8000"
|
value: "8000"
|
||||||
- key: DB_PATH
|
- key: DB_PATH
|
||||||
value: "/app/data/numerology.db"
|
value: "/workspace/data/numerology.db"
|
||||||
- key: JWT_SECRET
|
- key: JWT_SECRET
|
||||||
value: "xVtKLcdGpYdtoEjEBE9hFTJgBCJrEIu9AjXtAJMtwTU="
|
value: "xVtKLcdGpYdtoEjEBE9hFTJgBCJrEIu9AjXtAJMtwTU="
|
||||||
- key: JWT_EXPIRES_IN
|
- key: JWT_EXPIRES_IN
|
||||||
@@ -27,7 +27,7 @@ services:
|
|||||||
value: "info"
|
value: "info"
|
||||||
volumes:
|
volumes:
|
||||||
- name: sqlite-data
|
- name: sqlite-data
|
||||||
mount_path: /app/data
|
mount_path: /workspace/data
|
||||||
size: 1GB
|
size: 1GB
|
||||||
health_check:
|
health_check:
|
||||||
http:
|
http:
|
||||||
|
|||||||
@@ -5,16 +5,29 @@ const fs = require('fs');
|
|||||||
class DatabaseManager {
|
class DatabaseManager {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.db = null;
|
this.db = null;
|
||||||
// 生产环境使用持久化存储路径,开发环境使用本地路径
|
|
||||||
this.dbPath = process.env.NODE_ENV === 'production'
|
// 检测Koyeb环境并使用正确的挂载路径
|
||||||
? '/app/data/numerology.db'
|
const isKoyeb = process.env.KOYEB_APP_NAME || process.env.KOYEB_SERVICE_NAME || fs.existsSync('/workspace/data');
|
||||||
: path.join(__dirname, '../../numerology.db');
|
|
||||||
|
if (isKoyeb) {
|
||||||
|
// Koyeb环境:Volume挂载到/workspace/data
|
||||||
|
this.dbPath = '/workspace/data/numerology.db';
|
||||||
|
} else if (process.env.NODE_ENV === 'production') {
|
||||||
|
// 其他生产环境:使用/app/data
|
||||||
|
this.dbPath = '/app/data/numerology.db';
|
||||||
|
} else {
|
||||||
|
// 开发环境:使用本地路径
|
||||||
|
this.dbPath = path.join(__dirname, '../../numerology.db');
|
||||||
|
}
|
||||||
|
|
||||||
this.schemaPath = path.join(__dirname, 'schema.sql');
|
this.schemaPath = path.join(__dirname, 'schema.sql');
|
||||||
|
|
||||||
// 输出数据库配置信息
|
// 输出数据库配置信息
|
||||||
console.log(`🗄️ 数据库路径: ${this.dbPath}`);
|
console.log(`🗄️ 数据库路径: ${this.dbPath}`);
|
||||||
console.log(`🌍 运行环境: ${process.env.NODE_ENV || 'development'}`);
|
console.log(`🌍 运行环境: ${process.env.NODE_ENV || 'development'}`);
|
||||||
console.log(`📊 数据库文件: ${path.basename(this.dbPath)}`);
|
console.log(`📊 数据库文件: ${path.basename(this.dbPath)}`);
|
||||||
|
console.log(`🏢 Koyeb环境: ${isKoyeb ? 'Yes' : 'No'}`);
|
||||||
|
console.log(`📁 工作目录: ${process.cwd()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化数据库连接
|
// 初始化数据库连接
|
||||||
|
|||||||
Reference in New Issue
Block a user