-
-
Notifications
You must be signed in to change notification settings - Fork 181
Fix/drizzle migrations idempotent #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3edd6b7
9e384ad
396fc0f
5512501
bcc0f90
85ace2e
5eef400
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| 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); |
| 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; |
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 与其他迁移文件相同,此文件也被手动编辑以添加 正确的做法是:
基于学习记录和编码规范。 🤖 Prompt for AI Agents |
||
| 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; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 严重问题:违反了代码规范,不应手动编辑生成的迁移文件 与 手动编辑历史迁移文件会导致迁移历史不一致,并且在重新生成迁移时这些修改会丢失。 建议:
根据代码规范说明。 🤖 Prompt for AI Agents |
||
| 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ding113/claude-code-hub
Length of output: 1696
🏁 Script executed:
Repository: ding113/claude-code-hub
Length of output: 2353
🏁 Script executed:
Repository: ding113/claude-code-hub
Length of output: 3758
🏁 Script executed:
Repository: ding113/claude-code-hub
Length of output: 5020
🏁 Script executed:
Repository: ding113/claude-code-hub
Length of output: 879
❌ 违反编码规范:禁止手动编辑 SQL 迁移文件
根据项目编码规范,SQL 迁移文件必须通过以下流程生成,不能手动编辑:
src/drizzle/schema.tsbun run db:generate生成迁移bun run db:migrate该迁移文件使用了
IF NOT EXISTS子句进行手动编辑以实现幂等性,这会导致:应创建新的迁移文件而非修改现有迁移,或在应用层面处理幂等性逻辑。
🤖 Prompt for AI Agents