claude-code-hub
claude-code-hub copied to clipboard
最新版0.2.26升级时数据库迁移失败, 导致服务起不来
claude-code-hub-app | {"level":"error","time":1762089970517,"pid":1,"hostname":"4c176697b855","err":{"type":"y","message":"Failed query: CREATE TABLE \"notification_settings\" (\n\t\"id\" serial PRIMARY KEY NOT NULL,\n\t\"enabled\" boolean DEFAULT false NOT NULL,\n\t\"circuit_breaker_enabled\" boolean DEFAULT false NOT NULL,\n\t\"circuit_breaker_webhook\" varchar(512),\n\t\"daily_leaderboard_enabled\" boolean DEFAULT false NOT NULL,\n\t\"daily_leaderboard_webhook\" varchar(512),\n\t\"daily_leaderboard_time\" varchar(10) DEFAULT '09:00',\n\t\"daily_leaderboard_top_n\" integer DEFAULT 5,\n\t\"cost_alert_enabled\" boolean DEFAULT false NOT NULL,\n\t\"cost_alert_webhook\" varchar(512),\n\t\"cost_alert_threshold\" numeric(5, 2) DEFAULT '0.80',\n\t\"cost_alert_check_interval\" integer DEFAULT 60,\n\t\"created_at\" timestamp with time zone DEFAULT now(),\n\t\"updated_at\" timestamp with time zone DEFAULT now()\n);\n\nparams: : relation \"notification_settings\" already exists","stack":"Error: Failed query: CREATE TABLE \"notification_settings\" (\n\t\"id\" serial PRIMARY KEY NOT NULL,\n\t\"enabled\" boolean DEFAULT false NOT NULL,\n\t\"circuit_breaker_enabled\" boolean DEFAULT false NOT NULL,\n\t\"circuit_breaker_webhook\" varchar(512),\n\t\"daily_leaderboard_enabled\" boolean DEFAULT false NOT NULL,\n\t\"daily_leaderboard_webhook\" varchar(512),\n\t\"daily_leaderboard_time\" varchar(10) DEFAULT '09:00',\n\t\"daily_leaderboard_top_n\" integer DEFAULT 5,\n\t\"cost_alert_enabled\" boolean DEFAULT false NOT NULL,\n\t\"cost_alert_webhook\" varchar(512),\n\t\"cost_alert_threshold\" numeric(5, 2) DEFAULT '0.80',\n\t\"cost_alert_check_interval\" integer DEFAULT 60,\n\t\"created_at\" timestamp with time zone DEFAULT now(),\n\t\"updated_at\" timestamp with time zone DEFAULT now()\n);\n\nparams: \n at av.queryWithCache (/app/.next/server/chunks/1617.js:8:34779)\n at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n at async /app/.next/server/chunks/1617.js:8:359\n at async g (/app/.next/server/chunks/1617.js:35:10446)\n at async Function.E [as begin] (/app/.next/server/chunks/1617.js:35:10019)\n at async O.migrate (/app/.next/server/chunks/1617.js:8:245)\n at async g (/app/.next/server/chunks/780.js:1:753)\n at async m (/app/.next/server/chunks/780.js:1:1109)\n at async Module.e (/app/.next/server/instrumentation.js:36:12580)\n at async registerInstrumentation (/app/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-utils/instrumentation-globals.external.js:63:13)\ncaused by: k: relation \"notification_settings\" already exists\n at S (/app/.next/server/chunks/1617.js:18:2034)\n at /app/.next/server/chunks/1617.js:18:3080\n at Socket.aN (/app/.next/server/chunks/1617.js:18:3084)\n at Socket.emit (node:events:519:28)\n at addChunk (node:internal/streams/readable:561:12)\n at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)\n at Readable.push (node:internal/streams/readable:392:5)\n at TCP.onStreamRead (node:internal/stream_base_commons:189:23)","query":"CREATE TABLE \"notification_settings\" (\n\t\"id\" serial PRIMARY KEY NOT NULL,\n\t\"enabled\" boolean DEFAULT false NOT NULL,\n\t\"circuit_breaker_enabled\" boolean DEFAULT false NOT NULL,\n\t\"circuit_breaker_webhook\" varchar(512),\n\t\"daily_leaderboard_enabled\" boolean DEFAULT false NOT NULL,\n\t\"daily_leaderboard_webhook\" varchar(512),\n\t\"daily_leaderboard_time\" varchar(10) DEFAULT '09:00',\n\t\"daily_leaderboard_top_n\" integer DEFAULT 5,\n\t\"cost_alert_enabled\" boolean DEFAULT false NOT NULL,\n\t\"cost_alert_webhook\" varchar(512),\n\t\"cost_alert_threshold\" numeric(5, 2) DEFAULT '0.80',\n\t\"cost_alert_check_interval\" integer DEFAULT 60,\n\t\"created_at\" timestamp with time zone DEFAULT now(),\n\t\"updated_at\" timestamp with time zone DEFAULT now()\n);\n","params":[]},"msg":"❌ Migration failed:"}
格式化之后的报错,
Failed query: CREATE TABLE "notification_settings" (
"id" serial PRIMARY KEY NOT NULL,
"enabled" boolean DEFAULT false NOT NULL,
"circuit_breaker_enabled" boolean DEFAULT false NOT NULL,
"circuit_breaker_webhook" varchar(512),
"daily_leaderboard_enabled" boolean DEFAULT false NOT NULL,
"daily_leaderboard_webhook" varchar(512),
"daily_leaderboard_time" varchar(10) DEFAULT '09:00',
"daily_leaderboard_top_n" integer DEFAULT 5,
"cost_alert_enabled" boolean DEFAULT false NOT NULL,
"cost_alert_webhook" varchar(512),
"cost_alert_threshold" numeric(5, 2) DEFAULT '0.80',
"cost_alert_check_interval" integer DEFAULT 60,
"created_at" timestamp with time zone DEFAULT now(),
"updated_at" timestamp with time zone DEFAULT now()
);
params: : relation "notification_settings" already exists
问题已修复 ✅
我已经为这个迁移失败问题创建了修复 PR: #66
问题根源:
迁移文件 drizzle/0013_outgoing_justin_hammer.sql 缺少 IF NOT EXISTS 检查,导致增量升级时如果 notification_settings 表已存在,会抛出错误并退出。
修复方案:
CREATE TABLE IF NOT EXISTS "notification_settings" (...)
如何应用修复:
方法 1: 等待新版本发布 (推荐)
等待 PR 合并后的新版本,使用 docker compose pull && docker compose up -d 升级。
方法 2: 临时解决方案 (立即可用) 如果急需修复,可以手动修改迁移文件:
# 1. 进入容器
docker compose exec app sh
# 2. 修改迁移文件
sed -i "s/CREATE TABLE \"notification_settings\"/CREATE TABLE IF NOT EXISTS \"notification_settings\"/" /app/drizzle/0013_outgoing_justin_hammer.sql
# 3. 退出容器
exit
# 4. 重启服务
docker compose restart app
验证修复: 查看日志确认迁移成功完成:
docker compose logs app | grep -i migration
如果看到 "Database migrations completed successfully!" 说明修复成功。
有任何问题请在 Issue 或 PR 中反馈!
收到,稍后发版本解决。
麻烦更新一下 0.2.28 版本测试一下。