mirror of
https://github.com/patdelphi/suanming.git
synced 2026-02-28 05:33:11 +08:00
feat: 完善Koyeb数据库持久化配置
- 更新.koyeb/koyeb.yaml添加完整环境变量配置 - 添加DB_PATH明确指定生产环境数据库路径 - 增强数据库管理器日志输出,显示路径和环境信息 - 添加数据库目录创建状态日志 - 更新.env.example添加数据库配置说明 - 确保本地开发和Koyeb生产环境数据库路径正确分离 - 实现完整的数据库持久化方案
This commit is contained in:
@@ -11,6 +11,7 @@ JWT_SECRET=your-super-secret-jwt-key-change-in-production
|
||||
JWT_EXPIRES_IN=7d
|
||||
|
||||
# 数据库配置
|
||||
# 本地开发使用相对路径,生产环境自动使用 /app/data/numerology.db
|
||||
DB_PATH=./numerology.db
|
||||
|
||||
# 运行环境
|
||||
|
||||
@@ -17,6 +17,14 @@ services:
|
||||
value: production
|
||||
- key: PORT
|
||||
value: "8000"
|
||||
- key: DB_PATH
|
||||
value: "/app/data/numerology.db"
|
||||
- key: JWT_SECRET
|
||||
value: "xVtKLcdGpYdtoEjEBE9hFTJgBCJrEIu9AjXtAJMtwTU="
|
||||
- key: JWT_EXPIRES_IN
|
||||
value: "7d"
|
||||
- key: LOG_LEVEL
|
||||
value: "info"
|
||||
volumes:
|
||||
- name: sqlite-data
|
||||
mount_path: /app/data
|
||||
|
||||
@@ -10,6 +10,11 @@ class DatabaseManager {
|
||||
? '/app/data/numerology.db'
|
||||
: path.join(__dirname, '../../numerology.db');
|
||||
this.schemaPath = path.join(__dirname, 'schema.sql');
|
||||
|
||||
// 输出数据库配置信息
|
||||
console.log(`🗄️ 数据库路径: ${this.dbPath}`);
|
||||
console.log(`🌍 运行环境: ${process.env.NODE_ENV || 'development'}`);
|
||||
console.log(`📊 数据库文件: ${path.basename(this.dbPath)}`);
|
||||
}
|
||||
|
||||
// 初始化数据库连接
|
||||
@@ -19,6 +24,9 @@ class DatabaseManager {
|
||||
const dbDir = path.dirname(this.dbPath);
|
||||
if (!fs.existsSync(dbDir)) {
|
||||
fs.mkdirSync(dbDir, { recursive: true });
|
||||
console.log(`📁 创建数据库目录: ${dbDir}`);
|
||||
} else {
|
||||
console.log(`📁 数据库目录已存在: ${dbDir}`);
|
||||
}
|
||||
|
||||
// 创建或连接到SQLite数据库
|
||||
|
||||
Reference in New Issue
Block a user