Skip to content

PR: fix(db): make drizzle migrations idempotent#578

Merged
ding113 merged 2 commits intoding113:devfrom
YangQing-Lin:fix/drizzle-migrations-idempotent
Jan 10, 2026
Merged

PR: fix(db): make drizzle migrations idempotent#578
ding113 merged 2 commits intoding113:devfrom
YangQing-Lin:fix/drizzle-migrations-idempotent

Conversation

@YangQing-Lin
Copy link
Collaborator

@YangQing-Lin YangQing-Lin commented Jan 10, 2026

Summary

Makes Drizzle migrations idempotent by adding IF NOT EXISTS to ADD COLUMN statements, preventing "column already exists" errors during local development startup.

Problem

Local development startup (bun run dev) auto-executes Drizzle migrations. When certain columns already exist in the database, the corresponding migrations still attempt ADD COLUMN, causing errors like column ... already exists and failing the dev environment startup.

Related Issues/PRs:

Solution

Modified migration files to use ADD COLUMN IF NOT EXISTS syntax, allowing migrations to skip safely when columns already exist.

Changes

Migration Files Updated

File Column(s)
drizzle/0049_shocking_ultimatum.sql special_settings
drizzle/0050_flippant_jack_flag.sql enable_response_fixer, response_fixer_config
drizzle/0051_silent_maelstrom.sql enable_thinking_signature_rectifier
drizzle/0052_model_price_source.sql source (index already uses IF NOT EXISTS)

Other Changes

  • .gitignore: Added .codex/ directory

Breaking Changes

None. IF NOT EXISTS only affects migrations when columns already exist - it does not modify column types, defaults, or constraints.

Risks & Trade-offs

  • IF NOT EXISTS only skips when "column already exists", it will NOT auto-correct schema drift (e.g., mismatched types/defaults/NOT NULL). If alignment is needed, explicit ALTER COLUMN ... migrations should be added.

Testing

Manual Testing

bun run dev
# or just migrations:
bun run db:migrate

Expected: Migrations complete without "column already exists" errors.

Note: The author mentioned this fix was created after manually interrupting a dev startup, so a full startup cycle should be verified.

Checklist

  • Code follows project conventions
  • Self-review completed
  • Tests pass locally (bun run test)
  • No breaking changes

Description enhanced by Claude AI

Use ADD COLUMN IF NOT EXISTS in 0044_uneven_donald_blake.sql (line 1)
Use ADD COLUMN IF NOT EXISTS in 0049_shocking_ultimatum.sql (line 1)
Use ADD COLUMN IF NOT EXISTS in 0050_flippant_jack_flag.sql (line 1)
Use ADD COLUMN IF NOT EXISTS in 0051_silent_maelstrom.sql (line 1)
Use ADD COLUMN IF NOT EXISTS in 0052_model_price_source.sql (line 1)
@coderabbitai
Copy link

coderabbitai bot commented Jan 10, 2026

📝 Walkthrough

演练

在gitignore中添加了.codex/目录的忽略规则,同时对四个数据库迁移文件进行了修改,在ADD COLUMN语句中添加了IF NOT EXISTS子句,使这些操作具有幂等性。共涉及5个文件的变更。

变更

内聚 / 文件 变更摘要
Gitignore配置
.gitignore
在工具与日志部分新增+.codex/忽略规则
数据库迁移
drizzle/0049_shocking_ultimatum.sqldrizzle/0050_flippant_jack_flag.sqldrizzle/0051_silent_maelstrom.sqldrizzle/0052_model_price_source.sql
将ADD COLUMN语句修改为ADD COLUMN IF NOT EXISTS,使迁移操作在列已存在时具有幂等性;列的定义、默认值和约束保持不变

预估代码审查工作量

🎯 1 (Trivial) | ⏱️ ~3分钟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 标题清晰准确地总结了主要变更:将 Drizzle 数据库迁移改为幂等操作。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed PR description clearly explains the problem (idempotent migrations), solution (ADD COLUMN IF NOT EXISTS), affected files, and provides context about related issues and testing.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @YangQing-Lin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在解决本地开发环境中 Drizzle 数据库迁移的稳定性问题。通过修改现有的迁移脚本,使其在添加新列时具备幂等性,即当目标列已存在时,迁移操作将安全跳过而非抛出错误。这显著提升了开发工作流的顺畅性,避免了因重复执行迁移而导致的启动失败,从而为开发者提供了更可靠的数据库初始化体验。

Highlights

  • 数据库迁移幂等性: 将多个 Drizzle 数据库迁移文件中的 ADD COLUMN 语句修改为 ADD COLUMN IF NOT EXISTS,以确保在列已存在时不会报错,从而提高迁移的鲁棒性。
  • 开发环境稳定性: 修复了本地开发启动时,Drizzle 迁移因尝试添加已存在的列而导致报错并失败的问题,确保开发环境能够顺利启动。
  • .gitignore 更新: 在 .gitignore 文件中新增了 .codex/ 路径,用于忽略 Codex 相关文件。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions bot added the bug Something isn't working label Jan 10, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

您好,感谢您为解决数据库迁移幂等性问题所做的贡献。

本次 PR 的目标非常明确,即通过将 ADD COLUMN 修改为 ADD COLUMN IF NOT EXISTS 来避免在开发环境重复执行迁移时出错。您提交的修改是正确且有效的,能够解决所述问题。此外,我注意到您在修改 SQL 文件的同时,也为文件末尾添加了换行符,这是一个很好的实践。

有一个小问题需要您确认:PR 描述中提到了对 drizzle/0044_uneven_donald_blake.sql 文件的修改,但在本次提交的变更中似乎并未包含该文件。请检查一下是否遗漏了此文件的提交。

总体而言,这是一个高质量的修复,解决了开发流程中的一个痛点。在确认文件完整性并考虑我提出的建议后,即可合入。

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@github-actions github-actions bot added the size/S Small PR (< 200 lines) label Jan 10, 2026
@ding113 ding113 merged commit 0c682be into ding113:dev Jan 10, 2026
10 of 12 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Claude Code Hub Roadmap Jan 10, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code Review Summary

No significant issues identified in this PR.

PR Size: S

  • Lines changed: 13
  • Files changed: 5

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - Clean
  • Type safety - Clean
  • Documentation accuracy - Clean
  • Test coverage - Adequate
  • Code clarity - Good

Automated review by Codex AI

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

  • Reviewed PR #578 (fix/drizzle-migrations-idempotent) diff (5 files, 13 lines changed).
  • Applied PR size label: size/S.
  • Submitted a PR review comment via gh pr review (no inline comments posted because no issues met the reporting threshold in the diff).

NieiR added a commit to NieiR/claude-code-hub that referenced this pull request Jan 10, 2026
- PR ding113#580: TOML cloud price table + billing fail-open
- PR ding113#578: make drizzle migrations idempotent
- PR ding113#577: fix thinking enabled + tool_use first block
- PR ding113#573: add manual model price management

Conflict resolutions:
- drizzle migrations: use upstream idempotent version
- i18n messages: accept upstream additions
- price-sync.ts: removed (replaced by cloud-price-table)
- model-prices.ts: use upstream refactored version
@github-actions github-actions bot mentioned this pull request Jan 10, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size/S Small PR (< 200 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants