修复服务启动问题 + 添加数据库迁移脚本

修复:
- 分离数据库初始化逻辑到独立的 migrate.js
- 避免启动时索引创建顺序问题
- 服务启动不再自动运行 initDatabase

新增:
- migrate.js - 独立的数据库迁移脚本
- 先创建表,再添加外键,最后创建索引

使用方法:
1. 运行迁移: DB_HOST=localhost DB_PORT=5433 DB_NAME=agent_tasks_v2 node migrate.js
2. 启动服务: DB_HOST=localhost DB_PORT=5433 DB_NAME=agent_tasks_v2 node server-v2.js

已测试功能:
 全局规约设置和获取
 项目创建
 项目规约设置
 任务创建
 智能体注册
 任务领取(同时返回全局规约和项目规约)
This commit is contained in:
work-1
2026-02-15 21:45:22 +08:00
parent 6134a443a8
commit 0988350e66
2 changed files with 196 additions and 1 deletions
+2 -1
View File
@@ -57,7 +57,8 @@ pool.connect((err, client, release) => {
} else {
console.log('✅ 已连接到 PostgreSQL 数据库');
release();
initDatabase();
// 数据库表已通过 migrate.js 初始化
console.log('💡 提示: 如需初始化数据库,请运行: node migrate.js');
}
});