From 41f769744024cbca58f369ec2ccaade40c3d8ff7 Mon Sep 17 00:00:00 2001 From: patdelphi Date: Fri, 22 Aug 2025 23:43:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84Koyeb=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=8C=81=E4=B9=85=E5=8C=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新.koyeb/koyeb.yaml添加完整环境变量配置 - 添加DB_PATH明确指定生产环境数据库路径 - 增强数据库管理器日志输出,显示路径和环境信息 - 添加数据库目录创建状态日志 - 更新.env.example添加数据库配置说明 - 确保本地开发和Koyeb生产环境数据库路径正确分离 - 实现完整的数据库持久化方案 --- .env.example | 1 + .koyeb/koyeb.yaml | 8 ++++++++ server/database/index.cjs | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/.env.example b/.env.example index fb56025..1ef6903 100644 --- a/.env.example +++ b/.env.example @@ -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 # 运行环境 diff --git a/.koyeb/koyeb.yaml b/.koyeb/koyeb.yaml index 7874371..976603b 100644 --- a/.koyeb/koyeb.yaml +++ b/.koyeb/koyeb.yaml @@ -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 diff --git a/server/database/index.cjs b/server/database/index.cjs index 6eff2c3..d22d181 100644 --- a/server/database/index.cjs +++ b/server/database/index.cjs @@ -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数据库