Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ next-env.d.ts
# tooling & logs
.cursor/
.claude/
.codex/
.serena/
!src/app/dashboard/logs/
!src/app/settings/logs/
Expand Down
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,49 @@

---

## [v0.3.42](https://github.com/ding113/claude-code-hub/releases/tag/v0.3.42) - 2026-01-07

### 新增

- Session 详情页重设计,改进布局和用户体验 (f52a2651)
- 供应商级别参数覆写审计功能,支持 Codex reasoning/text/parallel_tool_calls 覆写 (#557, #536)
- 供应商查询缓存功能,支持缓存开关配置,默认启用 (#554, #556) [@hank9999](https://github.com/hank9999)
- Gemini 非流式错误规则 (#547) [@Kevin Cui](https://github.com/kevin-cui-tw)
- Anthropic Warmup 请求拦截功能 (#525)
- tool_use missing tool_result 错误规则 (#550, #551)
- Codex reasoning effort mismatch 错误规则 (#544)

### 优化

- 供应商保存异步架构重构,提升保存性能 (54bada89)
- 拆分 unified-edit-dialog 为专用对话框组件,改善代码结构 (#539) [@NieiR](https://github.com/NieiR)
- Session Messages 提升内容阈值并支持导出完整请求 (#537)
- 管理后台 UI 改进 (#538) [@miraserver](https://github.com/miraserver)

### 修复

- 修复 SessionStats 组件日期类型问题 (57ac4d6d)
- 修复 CodeDisplay 组件缺少 className prop (c622705b)
- 修复 /v1/responses 和 /v1/chat/completions 未使用 GuardPipeline 的问题 (#552)
- 修复添加新供应商后列表未刷新的问题 (#546) [@NieiR](https://github.com/NieiR)
- 补齐 system_settings 缺失列 (17014402)
- 修复供应商总限额编辑、生效和重置逻辑 (#535)
- 修复 Key 清除到期时间使用空字符串传参问题 (#534)
- 修复 my-usage 今日统计与只读 API 自助查询 (#532)
- 修复清除用户/Key 到期时间后保存不生效的问题 (#533)
- 修复用户限额未设置时 Key 限额仍生效的问题 (#531)
- 修复供应商搜索框重复清除按钮 (af17948d)
- 修复 CodeRabbit webhook 反馈问题 (#527)

### 其他

- 为 available-models 工具函数添加单元测试 (#528) [@NieiR](https://github.com/NieiR)
- 更新使用文档中 Codex 模型配置 (#545)
- 更新 AGENT 指导文档 (cc32b47b)
- 重新生成 blocked_by 索引迁移 (3250f210)

---

## [v0.3.41](https://github.com/ding113/claude-code-hub/releases/tag/v0.3.41) - 2026-01-03

### 新增
Expand Down
52 changes: 26 additions & 26 deletions drizzle/0000_legal_brother_voodoo.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE "keys" (
CREATE TABLE IF NOT EXISTS "keys" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"key" varchar NOT NULL,
Expand All @@ -14,7 +14,7 @@ CREATE TABLE "keys" (
"deleted_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "message_request" (
CREATE TABLE IF NOT EXISTS "message_request" (
"id" serial PRIMARY KEY NOT NULL,
"provider_id" integer NOT NULL,
"user_id" integer NOT NULL,
Expand All @@ -35,15 +35,15 @@ CREATE TABLE "message_request" (
"deleted_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "model_prices" (
CREATE TABLE IF NOT EXISTS "model_prices" (
"id" serial PRIMARY KEY NOT NULL,
"model_name" varchar NOT NULL,
"price_data" jsonb NOT NULL,
"created_at" timestamp with time zone DEFAULT now(),
"updated_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "providers" (
CREATE TABLE IF NOT EXISTS "providers" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar NOT NULL,
"description" text,
Expand All @@ -69,15 +69,15 @@ CREATE TABLE "providers" (
"deleted_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "system_settings" (
CREATE TABLE IF NOT EXISTS "system_settings" (
"id" serial PRIMARY KEY NOT NULL,
"site_title" varchar(128) DEFAULT 'Claude Code Hub' NOT NULL,
"allow_global_usage_view" boolean DEFAULT true NOT NULL,
"created_at" timestamp with time zone DEFAULT now(),
"updated_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "users" (
CREATE TABLE IF NOT EXISTS "users" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar NOT NULL,
"description" text,
Expand All @@ -90,23 +90,23 @@ CREATE TABLE "users" (
"deleted_at" timestamp with time zone
);
--> statement-breakpoint
CREATE INDEX "idx_keys_user_id" ON "keys" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX "idx_keys_created_at" ON "keys" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX "idx_keys_deleted_at" ON "keys" USING btree ("deleted_at");--> statement-breakpoint
CREATE INDEX "idx_message_request_user_date_cost" ON "message_request" USING btree ("user_id","created_at","cost_usd") WHERE "message_request"."deleted_at" IS NULL;--> statement-breakpoint
CREATE INDEX "idx_message_request_user_query" ON "message_request" USING btree ("user_id","created_at") WHERE "message_request"."deleted_at" IS NULL;--> statement-breakpoint
CREATE INDEX "idx_message_request_provider_id" ON "message_request" USING btree ("provider_id");--> statement-breakpoint
CREATE INDEX "idx_message_request_user_id" ON "message_request" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX "idx_message_request_key" ON "message_request" USING btree ("key");--> statement-breakpoint
CREATE INDEX "idx_message_request_created_at" ON "message_request" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX "idx_message_request_deleted_at" ON "message_request" USING btree ("deleted_at");--> statement-breakpoint
CREATE INDEX "idx_model_prices_latest" ON "model_prices" USING btree ("model_name","created_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "idx_model_prices_model_name" ON "model_prices" USING btree ("model_name");--> statement-breakpoint
CREATE INDEX "idx_model_prices_created_at" ON "model_prices" USING btree ("created_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "idx_providers_enabled_priority" ON "providers" USING btree ("is_enabled","priority","weight") WHERE "providers"."deleted_at" IS NULL;--> statement-breakpoint
CREATE INDEX "idx_providers_group" ON "providers" USING btree ("group_tag") WHERE "providers"."deleted_at" IS NULL;--> statement-breakpoint
CREATE INDEX "idx_providers_created_at" ON "providers" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX "idx_providers_deleted_at" ON "providers" USING btree ("deleted_at");--> statement-breakpoint
CREATE INDEX "idx_users_active_role_sort" ON "users" USING btree ("deleted_at","role","id") WHERE "users"."deleted_at" IS NULL;--> statement-breakpoint
CREATE INDEX "idx_users_created_at" ON "users" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX "idx_users_deleted_at" ON "users" USING btree ("deleted_at");
CREATE INDEX IF NOT EXISTS "idx_keys_user_id" ON "keys" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_keys_created_at" ON "keys" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_keys_deleted_at" ON "keys" USING btree ("deleted_at");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_message_request_user_date_cost" ON "message_request" USING btree ("user_id","created_at","cost_usd") WHERE "message_request"."deleted_at" IS NULL;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_message_request_user_query" ON "message_request" USING btree ("user_id","created_at") WHERE "message_request"."deleted_at" IS NULL;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_message_request_provider_id" ON "message_request" USING btree ("provider_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_message_request_user_id" ON "message_request" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_message_request_key" ON "message_request" USING btree ("key");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_message_request_created_at" ON "message_request" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_message_request_deleted_at" ON "message_request" USING btree ("deleted_at");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_model_prices_latest" ON "model_prices" USING btree ("model_name","created_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_model_prices_model_name" ON "model_prices" USING btree ("model_name");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_model_prices_created_at" ON "model_prices" USING btree ("created_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_providers_enabled_priority" ON "providers" USING btree ("is_enabled","priority","weight") WHERE "providers"."deleted_at" IS NULL;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_providers_group" ON "providers" USING btree ("group_tag") WHERE "providers"."deleted_at" IS NULL;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_providers_created_at" ON "providers" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_providers_deleted_at" ON "providers" USING btree ("deleted_at");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_users_active_role_sort" ON "users" USING btree ("deleted_at","role","id") WHERE "users"."deleted_at" IS NULL;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_users_created_at" ON "users" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_users_deleted_at" ON "users" USING btree ("deleted_at");
4 changes: 2 additions & 2 deletions drizzle/0001_ambiguous_bromley.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ALTER TABLE "message_request" ADD COLUMN "session_id" varchar(64);--> statement-breakpoint
CREATE INDEX "idx_message_request_session_id" ON "message_request" USING btree ("session_id") WHERE "message_request"."deleted_at" IS NULL;
ALTER TABLE "message_request" ADD COLUMN IF NOT EXISTS "session_id" varchar(64);--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_message_request_session_id" ON "message_request" USING btree ("session_id") WHERE "message_request"."deleted_at" IS NULL;
Comment on lines +1 to +2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check project structure and Drizzle setup
echo "=== Project root structure ==="
ls -la | head -20

echo -e "\n=== Check for drizzle directory ==="
fd -t d "drizzle" -E node_modules

echo -e "\n=== Check for drizzle configuration files ==="
fd -t f "drizzle\.config" -E node_modules

echo -e "\n=== Check package.json for Drizzle and db commands ==="
cat package.json | grep -A 5 '"scripts"'

Repository: ding113/claude-code-hub

Length of output: 1696


🏁 Script executed:

#!/bin/bash
# Examine the migration file in question
echo "=== Content of migration file ==="
cat -n drizzle/0001_ambiguous_bromley.sql

echo -e "\n=== Check if schema.ts exists ==="
find . -name "schema.ts" -o -name "schema.js" | head -5

echo -e "\n=== List all drizzle SQL files ==="
fd -t f "\.sql$" drizzle/

Repository: ding113/claude-code-hub

Length of output: 2353


🏁 Script executed:

#!/bin/bash
# Check schema definition
echo "=== Check for src/drizzle/schema.ts ==="
if [ -f "src/drizzle/schema.ts" ]; then
  wc -l src/drizzle/schema.ts
  echo "--- First 100 lines ---"
  head -100 src/drizzle/schema.ts
else
  echo "File not found, searching for schema files..."
  fd -t f "schema\.(ts|js)" -E node_modules
fi

Repository: ding113/claude-code-hub

Length of output: 3758


🏁 Script executed:

#!/bin/bash
# Find message_request table definition in schema.ts
echo "=== Search for message_request table in schema.ts ==="
rg -n "message_request" src/drizzle/schema.ts -A 30 | head -100

echo -e "\n=== Search for session_id in schema.ts ==="
rg -n "session_id" src/drizzle/schema.ts -B 2 -A 2

Repository: ding113/claude-code-hub

Length of output: 5020


🏁 Script executed:

#!/bin/bash
# Check for drizzle metadata files that track migrations
echo "=== Check for drizzle metadata directory ==="
ls -la drizzle/ | grep -E "meta|\.migrations"

echo -e "\n=== Check drizzle config content ==="
cat drizzle.config.ts

echo -e "\n=== Check if there's a git history for this migration file ==="
git log --oneline drizzle/0001_ambiguous_bromley.sql | head -5

Repository: ding113/claude-code-hub

Length of output: 879


❌ 违反编码规范:禁止手动编辑 SQL 迁移文件

根据项目编码规范,SQL 迁移文件必须通过以下流程生成,不能手动编辑:

  1. 编辑 src/drizzle/schema.ts
  2. 运行 bun run db:generate 生成迁移
  3. 审查生成的 SQL
  4. 运行 bun run db:migrate

该迁移文件使用了 IF NOT EXISTS 子句进行手动编辑以实现幂等性,这会导致:

  • Drizzle ORM 的迁移版本追踪与实际状态不一致
  • schema 定义与迁移脚本失去同步
  • 若这些迁移已在生产环境执行,重新运行或状态检查可能产生问题
  • 迁移元数据与实际代码脱节

应创建新的迁移文件而非修改现有迁移,或在应用层面处理幂等性逻辑。

🤖 Prompt for AI Agents
In @drizzle/0001_ambiguous_bromley.sql around lines 1 - 2, The migration file
drizzlle SQL was manually edited to add "session_id" and an index
"idx_message_request_session_id" using IF NOT EXISTS; revert this manual change
and instead add the new column and index in the schema source
(src/drizzle/schema.ts) so Drizzle can generate a proper migration, then run
"bun run db:generate" to create a new migration (do not hand-edit IF NOT
EXISTS), review the generated SQL, and apply it with "bun run db:migrate";
ensure the existing migration file is not modified directly so migration
metadata stays consistent.

10 changes: 5 additions & 5 deletions drizzle/0003_outstanding_centennial.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE "sensitive_words" (
CREATE TABLE IF NOT EXISTS "sensitive_words" (
"id" serial PRIMARY KEY NOT NULL,
"word" varchar(255) NOT NULL,
"match_type" varchar(20) DEFAULT 'contains' NOT NULL,
Expand All @@ -8,7 +8,7 @@ CREATE TABLE "sensitive_words" (
"updated_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN "blocked_by" varchar(50);--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN "blocked_reason" text;--> statement-breakpoint
CREATE INDEX "idx_sensitive_words_enabled" ON "sensitive_words" USING btree ("is_enabled","match_type");--> statement-breakpoint
CREATE INDEX "idx_sensitive_words_created_at" ON "sensitive_words" USING btree ("created_at");
ALTER TABLE "message_request" ADD COLUMN IF NOT EXISTS "blocked_by" varchar(50);--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN IF NOT EXISTS "blocked_reason" text;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_sensitive_words_enabled" ON "sensitive_words" USING btree ("is_enabled","match_type");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_sensitive_words_created_at" ON "sensitive_words" USING btree ("created_at");
2 changes: 1 addition & 1 deletion drizzle/0004_dazzling_starbolt.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE "message_request" ADD COLUMN "cost_multiplier" numeric(10, 4);
ALTER TABLE "message_request" ADD COLUMN IF NOT EXISTS "cost_multiplier" numeric(10, 4);
6 changes: 3 additions & 3 deletions drizzle/0005_true_raza.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ALTER TABLE "message_request" ADD COLUMN "original_model" varchar(128);--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN "user_agent" varchar(512);--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN "messages_count" integer;
ALTER TABLE "message_request" ADD COLUMN IF NOT EXISTS "original_model" varchar(128);--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN IF NOT EXISTS "user_agent" varchar(512);--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN IF NOT EXISTS "messages_count" integer;
38 changes: 19 additions & 19 deletions drizzle/0006_lame_matthew_murdock.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE "provider_schedule_logs" (
CREATE TABLE IF NOT EXISTS "provider_schedule_logs" (
"id" serial PRIMARY KEY NOT NULL,
"execution_time" timestamp with time zone NOT NULL,
"executed_by" varchar(50) NOT NULL,
Expand All @@ -11,21 +11,21 @@ CREATE TABLE "provider_schedule_logs" (
"created_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
ALTER TABLE "providers" ADD COLUMN "base_weight" integer;--> statement-breakpoint
ALTER TABLE "providers" ADD COLUMN "base_priority" integer;--> statement-breakpoint
ALTER TABLE "providers" ADD COLUMN "last_schedule_time" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "enable_auto_schedule" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "schedule_time" varchar(5) DEFAULT '02:00';--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "min_sample_size" integer DEFAULT 10;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "schedule_window_hours" integer DEFAULT 24;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "enable_realtime_schedule" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "schedule_interval_seconds" integer DEFAULT 30;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "exploration_rate" integer DEFAULT 15;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "circuit_recovery_weight_percent" integer DEFAULT 30;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "circuit_recovery_observation_count" integer DEFAULT 10;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "max_weight_adjustment_percent" integer DEFAULT 10;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "short_term_window_minutes" integer DEFAULT 60;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "medium_term_window_minutes" integer DEFAULT 360;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "long_term_window_minutes" integer DEFAULT 1440;--> statement-breakpoint
CREATE INDEX "idx_schedule_logs_execution_time" ON "provider_schedule_logs" USING btree ("execution_time" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "idx_schedule_logs_created_at" ON "provider_schedule_logs" USING btree ("created_at" DESC NULLS LAST);
ALTER TABLE "providers" ADD COLUMN IF NOT EXISTS "base_weight" integer;--> statement-breakpoint
ALTER TABLE "providers" ADD COLUMN IF NOT EXISTS "base_priority" integer;--> statement-breakpoint
ALTER TABLE "providers" ADD COLUMN IF NOT EXISTS "last_schedule_time" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "enable_auto_schedule" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "schedule_time" varchar(5) DEFAULT '02:00';--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "min_sample_size" integer DEFAULT 10;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "schedule_window_hours" integer DEFAULT 24;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "enable_realtime_schedule" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "schedule_interval_seconds" integer DEFAULT 30;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "exploration_rate" integer DEFAULT 15;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "circuit_recovery_weight_percent" integer DEFAULT 30;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "circuit_recovery_observation_count" integer DEFAULT 10;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "max_weight_adjustment_percent" integer DEFAULT 10;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "short_term_window_minutes" integer DEFAULT 60;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "medium_term_window_minutes" integer DEFAULT 360;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "long_term_window_minutes" integer DEFAULT 1440;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_schedule_logs_execution_time" ON "provider_schedule_logs" USING btree ("execution_time" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_schedule_logs_created_at" ON "provider_schedule_logs" USING btree ("created_at" DESC NULLS LAST);
34 changes: 17 additions & 17 deletions drizzle/0007_lazy_post.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
DROP TABLE "provider_schedule_logs" CASCADE;--> statement-breakpoint
ALTER TABLE "providers" DROP COLUMN "base_weight";--> statement-breakpoint
ALTER TABLE "providers" DROP COLUMN "base_priority";--> statement-breakpoint
ALTER TABLE "providers" DROP COLUMN "last_schedule_time";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "enable_auto_schedule";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "schedule_time";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "min_sample_size";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "schedule_window_hours";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "enable_realtime_schedule";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "schedule_interval_seconds";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "exploration_rate";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "circuit_recovery_weight_percent";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "circuit_recovery_observation_count";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "max_weight_adjustment_percent";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "short_term_window_minutes";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "medium_term_window_minutes";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN "long_term_window_minutes";
DROP TABLE IF EXISTS "provider_schedule_logs" CASCADE;--> statement-breakpoint
ALTER TABLE "providers" DROP COLUMN IF EXISTS "base_weight";--> statement-breakpoint
ALTER TABLE "providers" DROP COLUMN IF EXISTS "base_priority";--> statement-breakpoint
ALTER TABLE "providers" DROP COLUMN IF EXISTS "last_schedule_time";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "enable_auto_schedule";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "schedule_time";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "min_sample_size";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "schedule_window_hours";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "enable_realtime_schedule";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "schedule_interval_seconds";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "exploration_rate";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "circuit_recovery_weight_percent";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "circuit_recovery_observation_count";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "max_weight_adjustment_percent";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "short_term_window_minutes";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "medium_term_window_minutes";--> statement-breakpoint
ALTER TABLE "system_settings" DROP COLUMN IF EXISTS "long_term_window_minutes";
Comment on lines +1 to +17
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

⚠️ 手动编辑迁移文件违反了编码规范。

与其他迁移文件相同,此文件也被手动编辑以添加 IF EXISTS 子句。虽然这些更改在语法上是正确的,但手动修改现有迁移文件违反了项目的迁移生成工作流程。

正确的做法是:

  1. 修改 src/drizzle/schema.ts
  2. 运行 bun run db:generate 生成迁移
  3. 审查生成的 SQL
  4. 运行 bun run db:migrate

基于学习记录和编码规范。

🤖 Prompt for AI Agents
In @drizzle/0007_lazy_post.sql around lines 1 - 17, This migration file was
manually edited to add IF EXISTS to statements (e.g., DROP TABLE
"provider_schedule_logs", ALTER TABLE "providers" DROP COLUMN "base_weight",
ALTER TABLE "system_settings" DROP COLUMN "exploration_rate", etc.); revert
these manual edits and instead update the canonical schema
(src/drizzle/schema.ts) to reflect the desired nullable/optional columns or
removals, then run the project migration generator (bun run db:generate), verify
the generated SQL includes the IF EXISTS changes, and apply via bun run
db:migrate so the migration history remains consistent with the project's
workflow.

2 changes: 1 addition & 1 deletion drizzle/0008_talented_molten_man.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE "keys" ADD COLUMN "can_login_web_ui" boolean DEFAULT true;
ALTER TABLE "keys" ADD COLUMN IF NOT EXISTS "can_login_web_ui" boolean DEFAULT true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

严重问题:违反了代码规范,不应手动编辑生成的迁移文件

drizzle/0041_sticky_jackal.sql 相同的问题:SQL 迁移文件不应该手动编辑。正确的做法是编辑 src/drizzle/schema.ts,然后运行 bun run db:generatebun run db:migrate

手动编辑历史迁移文件会导致迁移历史不一致,并且在重新生成迁移时这些修改会丢失。

建议:

  • 在应用层面处理迁移的幂等性
  • 或使用 Drizzle 提供的机制来管理 schema 变更
  • 不要直接修改已生成的迁移文件

根据代码规范说明。

🤖 Prompt for AI Agents
In @drizzle/0008_talented_molten_man.sql at line 1, Do not manually edit the
generated migration file 0008_talented_molten_man.sql; instead revert this
change and make the schema change in src/drizzle/schema.ts (update the Keys
table definition to add the can_login_web_ui boolean default true), then
regenerate and apply migrations by running the project scripts (bun run
db:generate and bun run db:migrate) so the migration is produced correctly and
history remains consistent.

2 changes: 1 addition & 1 deletion drizzle/0009_many_amazoness.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE "providers" ADD COLUMN "allowed_models" jsonb DEFAULT 'null'::jsonb;
ALTER TABLE "providers" ADD COLUMN IF NOT EXISTS "allowed_models" jsonb DEFAULT 'null'::jsonb;
Loading
Loading