Skip to content

Conversation

weibaohui
Copy link
Owner

移除HelmRepository.UpdateContent方法及相关迁移代码
更新air配置排除.env文件

移除HelmRepository.UpdateContent方法及相关迁移代码
更新air配置排除.env文件
Copy link
Contributor

coderabbitai bot commented Aug 10, 2025

Warning

Rate limit exceeded

@weibaohui has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 46 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b11f602 and c20b128.

📒 Files selected for processing (1)
  • docs/database.md (3 hunks)
📝 Walkthrough

Summary by CodeRabbit

  • 新功能

    • 新增支持通过环境变量或命令行参数自定义 SQLite DSN(Data Source Name),可优先于原有的数据库文件路径设置。
    • 增加 --sqlite-dsn 启动参数,支持高级 SQLite 配置(如 WAL 模式、busy_timeout 等)。
  • 文档

    • 完善并细化 SQLite 配置说明,包括基础配置、高级配置、并发写入优化及注意事项。
    • 优化 MySQL 和 PostgreSQL 配置参数表格的排版格式。
  • 优化

    • 默认启用 SQLite WAL 模式并设置 busy_timeout=5000ms,提升并发写入性能,减少“database is locked”错误。
  • 其他

    • 移除 Helm 仓库模型的 content 字段相关遗留处理逻辑。
    • 调整 Air 热重载配置,.env 文件变更不再触发重载。

Walkthrough

本次变更涉及 Air 配置新增 .env 文件排除规则,.env.example 默认数据库驱动改为 SQLite,新增 SQLite DSN 配置支持,SQLite 连接初始化启用 WAL 模式和超时设置,移除 HelmRepository 的 UpdateContent 方法,注释 MySQL 下 content 字段迁移逻辑,以及扩充和格式化数据库相关文档。

Changes

Cohort / File(s) Change Summary
Air 配置文件调整
.air.toml
exclude_file 增加 .env,使 Air 忽略 .env 文件的变动。
环境变量示例文件
.env.example
数据库驱动默认值从 postgresql 改为 sqlite,其余未变。
SQLite 连接初始化与配置
internal/dao/conn.go, pkg/flag/flag.go
新增 SqliteDSN 配置字段及命令行参数支持,自定义 SQLite DSN;连接初始化优先使用 DSN,默认启用 WAL 模式和超时设置。
HelmRepository 相关模型方法
pkg/models/helm_repository.go
移除了 HelmRepositoryUpdateContent 方法。
数据库迁移逻辑调整
pkg/models/migrate.go
注释掉了针对 MySQL 的 content 字段 LONGTEXT 迁移逻辑,并说明该字段已移除。
数据库文档更新
docs/database.md
扩充 SQLite 配置文档,新增基础配置、并发写入优化和注意事项章节;优化 MySQL 和 PostgreSQL 环境变量表的 Markdown 格式。

Sequence Diagram(s)

sequenceDiagram
    participant Dev as 开发者
    participant Air as Air 热重载
    Dev->>Air: 保存 .env 文件
    Air-->>Dev: 不触发重载(因已被 exclude)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 分钟

Poem

🐰
配置微调如春风,
数据库切换轻松松。
WAL 模式添新意,
DSN 参数更灵通。
旧方法悄然离场,
文档丰富更详尽,
兔子欢跳庆变更!
🌱📦✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-db

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
.air.toml (1)

10-10: 建议同时排除 .env. 变体文件,避免开发时误触发重载*

不少团队会使用 .env.local / .env.development 等文件,建议一并排除。

-exclude_file = ["*.test", ".env"]
+exclude_file = ["*.test", ".env", ".env.*"]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9cee4cd and 220922c.

📒 Files selected for processing (4)
  • .air.toml (1 hunks)
  • .env.example (1 hunks)
  • pkg/models/helm_repository.go (0 hunks)
  • pkg/models/migrate.go (1 hunks)
💤 Files with no reviewable changes (1)
  • pkg/models/helm_repository.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
.env.example (1)

32-32: 改为 sqlite 默认值与PR目标一致,变更合理

默认DB切至sqlite与本次重构目标一致,便于开箱即用。

.air.toml (1)

10-10: 本次调整方向正确

忽略 .env 可避免开发过程因环境变量微调导致的频繁重编译,体验更稳定。

pkg/models/migrate.go (1)

59-62: 确认已移除 HelmRepository.content 字段,且无 UpdateContent 方法或字段引用
– 在 pkg/models/helm_repository.go 中,HelmRepository 结构体已不含 Content 字段
– 全仓库搜索未发现 UpdateContent 方法或对模型 content 字段的任何调用或引用
可以安心保留迁移脚本中注释掉的老逻辑,无需额外修改。

@@ -29,7 +29,7 @@ NODE_SHELL_IMAGE=alpine:latest


# 数据库类型(sqlite、mysql、postgresql等)
DB_DRIVER=postgresql
DB_DRIVER=sqlite
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

建议补充 sqlite 并发与文件路径注意事项(WAL、busy_timeout、目录存在性)

为减少多并发写入“database is locked”等问题,建议:

  • 在 README 或 .env.example 注释中提示开启 WAL 模式与 busy_timeout;
  • 确保 ./data 目录在启动前已创建;
  • 如代码侧支持参数化,提供一个可选的 DSN/PRAGMA 环境变量(例如 SQLITE_DSN 或 SQLITE_PARAMS)示例,包含 _journal_mode=WAL&busy_timeout=5000 等设置。

可选验证:确认代码是否已对 sqlite 进行 WAL/busy_timeout 配置。


🏁 Script executed:

#!/bin/bash
# 搜索项目内 sqlite 连接与参数设置位置,确认是否设置 WAL / busy_timeout 等
rg -n -A3 -B3 '(gorm\.Open|driver/sqlite|sqlite(_path|path|dsn|params|pragma|journal|busy_timeout))'

Length of output: 1091


补充 SQLite 并发与文件路径注意事项

在使用 DB_DRIVER=sqlite 时,建议在 .env.exampleREADME 中补充以下说明,以降低多并发写入时出现 “database is locked” 的风险,并保证数据库文件路径正确:

  • 在 DSN/PRAGMA 中开启 WAL 模式与设置写超时,例如:
    # 示例 .env.example
    SQLITE_DSN="file:./data/app.db?_journal_mode=WAL&busy_timeout=5000"
  • 启动前确保 ./data 目录已创建,否则 SQLite 无法自动创建父目录。
  • 如代码侧已支持参数化 DSN,可新增环境变量示例(如 SQLITE_DSNSQLITE_PARAMS),并在 internal/dao/conn.go 中使用:
    // internal/dao/conn.go
    db, err := gorm.Open(sqlite.Open(cfg.SqliteDsn), &gorm.Config{ Logger: customLogger })
  • 当前代码片段(见 internal/dao/conn.go:74)仅调用 sqlite.Open(cfg.SqlitePath),尚未显式配置 WAL 和 busy_timeout,建议一并传入上述参数。

请根据项目需求,补充文档与示例,并在代码启动逻辑中校验或创建 data 目录。

🤖 Prompt for AI Agents
In the .env.example file at line 32, add documentation and examples for SQLite
usage to reduce "database is locked" errors under concurrent writes and ensure
correct file paths. Include a sample environment variable like SQLITE_DSN with
WAL mode and busy_timeout parameters, e.g.,
"file:./data/app.db?_journal_mode=WAL&busy_timeout=5000". Also, update the
README or .env.example to remind users to create the ./data directory before
starting. In internal/dao/conn.go around line 74, modify the SQLite connection
to use the new DSN parameter instead of just the file path, enabling WAL and
timeout settings. Add code to check and create the ./data directory at startup
if it doesn't exist.

Comment on lines +59 to +62
// MYSQL 下需要单独处理 content字段为LONGTEXT,pg、sqlite不需要处理,这个字段删掉了,不用了
// if dao.DB().Migrator().HasTable(&HelmRepository{}) && dao.DB().Dialector.Name() == "mysql" {
// dao.DB().Exec("ALTER TABLE helm_repositories MODIFY COLUMN content LONGTEXT")
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议用明确的数据迁移替换注释代码:在支持的驱动上删除已废弃的 content 列

既然 content 字段已废弃,建议在 MySQL/PostgreSQL 上显式清理历史列,减少“僵尸列”带来的维护成本与困惑。对于 SQLite,可跳过(或仅在 SQLite 3.35+ 时执行),以避免潜在不兼容。

可在当前位置替换为如下逻辑(沿用本函数 errs 聚合方式):

-	// MYSQL 下需要单独处理 content字段为LONGTEXT,pg、sqlite不需要处理,这个字段删掉了,不用了
-	// if dao.DB().Migrator().HasTable(&HelmRepository{}) && dao.DB().Dialector.Name() == "mysql" {
-	// 	dao.DB().Exec("ALTER TABLE helm_repositories MODIFY COLUMN content LONGTEXT")
-	// }
+	// 兼容历史库:content 字段已废弃,支持的驱动上清理历史列(避免遗留“僵尸列”)
+	if dao.DB().Migrator().HasTable(&HelmRepository{}) {
+		name := dao.DB().Dialector.Name()
+		if (name == "mysql" || name == "postgres") && dao.DB().Migrator().HasColumn(&HelmRepository{}, "content") {
+			if err := dao.DB().Migrator().DropColumn(&HelmRepository{}, "content"); err != nil {
+				errs = append(errs, err)
+			}
+		}
+		// 注意:SQLite 对 DropColumn 依赖 3.35+,如需支持可在此按版本/驱动差异化处理
+	}
🤖 Prompt for AI Agents
In pkg/models/migrate.go around lines 59 to 62, replace the commented-out code
with explicit migration logic that drops the deprecated content column on
supported databases like MySQL and PostgreSQL, while skipping or conditionally
handling SQLite based on version. Implement this using the existing errs
aggregation pattern in the function to properly track errors during the
migration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
internal/dao/conn.go (1)

66-71: defer file.Close() 在错误检查前调用,err != nil 时可能触发空指针

os.Create 返回错误时,filenil,当前先 defer file.Close() 会导致 panic。应当先判断错误,再 defer。

- file, err := os.Create(cfg.SqlitePath)
- defer file.Close()
- if err != nil {
+ file, err := os.Create(cfg.SqlitePath)
+ if err != nil {
     klog.Errorf("创建数据库文件[%s]失败: %v", cfg.SqlitePath, err.Error())
     return nil, err
- }
+ }
+ defer file.Close()
🧹 Nitpick comments (1)
internal/dao/conn.go (1)

61-62: 目录权限过宽,建议从 0777(os.ModePerm)收紧为 0755

os.ModePerm 等同 0777,过于宽松。一般目录使用 0755 更合适,降低误用风险。

- err := os.MkdirAll(dir, os.ModePerm)
+ err := os.MkdirAll(dir, 0755)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 220922c and a8a46b5.

📒 Files selected for processing (2)
  • docs/database.md (3 hunks)
  • internal/dao/conn.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/dao/conn.go (1)
pkg/flag/flag.go (1)
  • Config (21-90)
🪛 LanguageTool
docs/database.md

[uncategorized] ~48-~48: 动词的修饰一般为‘形容词(副词)+地+动词’。您的意思是否是:正确"地"读
Context: ...*: 启动前请确保数据库文件所在目录 (如 ./data) 已存在且具有正确的读写权限。 2. 并发限制: SQLite 适合轻量级应用场景。如果您的...

(wb4)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
internal/dao/conn.go (1)

74-76: DSN 参数写法无需使用下划线前缀

glebarez/sqlite 驱动会自动将 busy_timeoutjournal_mode 查询参数映射为对应的 PRAGMA,所以无需改为 _busy_timeout_pragma,当前写法(busy_timeout=5000&journal_mode=WAL)已经生效。

如果想进一步优化并发,可在 DSN 中额外添加 cache=shared,例如:

- dsn := fmt.Sprintf("file:%s?_journal_mode=WAL&busy_timeout=5000", cfg.SqlitePath)
+ dsn := fmt.Sprintf("file:%s?cache=shared&busy_timeout=5000&journal_mode=WAL", cfg.SqlitePath)

无需手动执行 PRAGMA。

Likely an incorrect or invalid review comment.

docs/database.md (2)

61-71: MySQL 参数表格式化变更清晰可读,LGTM


93-102: PostgreSQL 参数表格式化变更清晰可读,LGTM

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (2)
docs/database.md (2)

41-48: DSN 示例参数名应为 _busy_timeout;可提供 _pragma 可选写法

当前示例使用 busy_timeout,可能不生效;应改为 _busy_timeout,或使用 _pragma。与 go-sqlite3 的实践保持一致。

建议改为:

-     SQLITE_DSN="file:./data/k8m.db?_journal_mode=WAL&busy_timeout=5000"
+     SQLITE_DSN="file:./data/k8m.db?cache=shared&_journal_mode=WAL&_busy_timeout=5000"
-     --sqlite-dsn="file:./data/k8m.db?_journal_mode=WAL&busy_timeout=5000"
+     --sqlite-dsn="file:./data/k8m.db?cache=shared&_journal_mode=WAL&_busy_timeout=5000"

也可在示例旁补充:或使用 _pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)


63-66: WAL 模式下直接 cp 备份可能不一致,改用 sqlite3 .backup 或 VACUUM INTO

在并发写入或 WAL 模式下,简单 cp 不能保证一致性快照,存在数据风险。

建议替换备份示例:

-3. **备份建议**: 建议定期备份数据库文件,可以通过以下命令进行备份:
-   ```shell
-   cp ./data/k8m.db ./data/k8m.db.backup
-   ```
+3. **备份建议**: 建议定期备份数据库文件,可使用以下任一方式获取一致性快照:
+   ```shell
+   # 方式一(推荐,通用)
+   sqlite3 ./data/k8m.db '.backup ./data/k8m.db.backup'
+
+   # 方式二(新版本 SQLite 支持)
+   sqlite3 ./data/k8m.db 'VACUUM INTO "./data/k8m.db.backup"'
+   ```
🧹 Nitpick comments (2)
docs/database.md (2)

52-58: 补充 cache=shared 建议,优化多连接并发读写体验

在多连接/多进程下,启用 shared cache 更易配合 WAL。

建议将本小节改为三点:

 1. WAL (Write-Ahead Logging) 模式
-2. busy_timeout 设置为 5000ms
+2. busy_timeout 设置为 5000ms
+3. 建议启用 cache=shared(例如 DSN 中追加 `cache=shared`),以改善多连接并发下的读写体验

61-61: 措辞微调:将“具有正确的读写权限”改为“具备正确的读写权限”

语义更顺滑,符合中文书面表达。

-1. **目录权限**: 启动前请确保数据库文件所在目录 (如 `./data`) 已存在且具有正确的读写权限。
+1. **目录权限**: 启动前请确保数据库文件所在目录 (如 `./data`) 已存在且具备正确的读写权限。
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8a46b5 and f4c6454.

📒 Files selected for processing (3)
  • docs/database.md (2 hunks)
  • internal/dao/conn.go (1 hunks)
  • pkg/flag/flag.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/dao/conn.go
🧰 Additional context used
🪛 LanguageTool
docs/database.md

[uncategorized] ~61-~61: 动词的修饰一般为‘形容词(副词)+地+动词’。您的意思是否是:正确"地"读
Context: ...*: 启动前请确保数据库文件所在目录 (如 ./data) 已存在且具有正确的读写权限。 2. 并发限制: SQLite 适合轻量级应用场景。如果您的...

(wb4)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
pkg/flag/flag.go (1)

57-58: 新增 SqliteDSN 字段设计合理,保持向后兼容

新增字段不影响现有 SqlitePath,扩展性好。建议在帮助文案与运行时日志里明确“DSN 优先级高于 Path”。

Comment on lines +173 to 174
defaultSqliteDSN := getEnv("SQLITE_DSN", "") // 默认为空,表示使用默认 DSN 配置

Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

请核对连接实现中的 DSN 参数是否与文档一致(_journal_mode、_busy_timeout 或 _pragma)

避免“文档用法”和“实际实现”不一致导致 busy_timeout 未生效。

建议运行以下脚本,检查 internal/dao/conn.go 中的 DSN 写法与示例一致性:


🏁 Script executed:

#!/bin/bash
# 查找 sqlite DSN / PRAGMA 相关设置是否包含 _journal_mode / _busy_timeout 或 _pragma
rg -n -A3 -B3 'SQLITE_DSN|SqliteDSN|journal_mode|busy_timeout|_pragma' internal/dao/conn.go || true

Length of output: 394


核对 SQLite DSN 参数与文档一致
默认 DSN 使用了 ? _journal_mode=WAL &busy_timeout=5000,但根据 Go SQLite 驱动(mattn/go-sqlite3/gorm.io/driver/sqlite)文档,busy_timeout 需带前导下划线(_busy_timeout)或通过 _pragma 方式指定,否则可能导致超时设置不生效。

请在 internal/dao/conn.go 中调整:

  • busy_timeout=5000 改为 _busy_timeout=5000
  • (可选)可改用 _pragma=busy_timeout(5000) 格式以匹配文档示例

示例 diff:

- dsn = fmt.Sprintf("file:%s?_journal_mode=WAL&busy_timeout=5000", cfg.SqlitePath)
+ dsn = fmt.Sprintf("file:%s?_journal_mode=WAL&_busy_timeout=5000", cfg.SqlitePath)

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In pkg/flag/flag.go around lines 173 to 174, the default SQLite DSN parameter
`busy_timeout=5000` does not follow the Go SQLite driver documentation which
requires a leading underscore. Update the DSN string to use `_busy_timeout=5000`
instead of `busy_timeout=5000`. Optionally, you can use the
`_pragma=busy_timeout(5000)` format to align with the documented examples. Make
sure this change is reflected in internal/dao/conn.go where the DSN is
constructed or used.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (2)
docs/database.md (2)

47-56: 高级 DSN 示例已采用带下划线参数,修复了此前 busy_timeout 未生效的风险

本段示例使用 _journal_mode_busy_timeout,与驱动要求一致,已避免早先“缺少前导下划线导致不生效”的问题。与“_pragma”风格并列展示也可接受。


69-86: 备份方法已改为 SQLite 原生命令并补充 WAL 注意事项,妥当

  • 使用 .backupVACUUM INTO,满足一致性备份要求。
  • 对 cp 的风险给出充分告警与步骤,实践上可接受。
  • 措辞“具备正确的读写权限”已较为顺畅。
🧹 Nitpick comments (1)
docs/database.md (1)

57-61: 更正“DNS”为“DSN”并消除裸链接(MD034);可补充统一风格说明

  • 将“更多DNS参数”更正为“更多 DSN 参数”。
  • 将裸链接改为 Markdown 链接,消除 MD034。
  • 可在此处说明:可选使用“带下划线参数”或“_pragma”两种风格(二选一即可),以减少读者困惑。

建议改动如下:

- > - 更多DNS参数,请参考https://github.com/glebarez/go-sqlite?tab=readme-ov-file#connection-string-examples
+ > - 更多 DSN 参数,请参考 [glebarez/go-sqlite 文档](https://github.com/glebarez/go-sqlite?tab=readme-ov-file#connection-string-examples)
+ > - DSN 可使用“带下划线参数”(如 `_busy_timeout=5000&_journal_mode=WAL`)或 `_pragma` 形式(如 `_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)`),任选其一保持一致即可。
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4c6454 and 765ed86.

📒 Files selected for processing (3)
  • docs/database.md (3 hunks)
  • internal/dao/conn.go (1 hunks)
  • pkg/flag/flag.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/dao/conn.go
  • pkg/flag/flag.go
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/database.md

7-7: Unordered list indentation
Expected: 0; Actual: 3

(MD007, ul-indent)


61-61: Bare URL used

(MD034, no-bare-urls)

🪛 LanguageTool
docs/database.md

[uncategorized] ~71-~71: 动词的修饰一般为‘形容词(副词)+地+动词’。您的意思是否是:正确"地"读
Context: ...*: 启动前请确保数据库文件所在目录 (如 ./data) 已存在且具备正确的读写权限。 2. 并发限制: SQLite 适合轻量级应用场景。如果您的...

(wb4)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (4)
docs/database.md (4)

33-46: SQLite 基础配置表述清晰,示例可用

基础配置(仅文件路径)与对应环境变量/启动参数示例清晰可用,无歧义。


62-68: 并发优化与实现一致,信息准确

明确启用 WAL 和将 busy_timeout 设为 5000ms。与实现目标一致。


94-105: MySQL 配置表格规范、参数齐全

表头、默认值与常见参数完整清晰,无明显问题。


126-135: PostgreSQL 配置表格规范、参数齐全

字段覆盖常用配置,默认值合理。

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
docs/database.md (1)

42-47: 保持 DSN 示例与实现顺序一致

实现中默认 DSN 顺序为 _pragma=busy_timeout(5000)&_pragma=journal_mode(WAL),建议将 docs/database.md 中的 SQLITE_DSN--sqlite-dsn 示例调整为相同顺序,以减少认知偏差。

待修改位置:

  • docs/database.md(第 42–47 行)

更新 diff 示例如下:

-     SQLITE_DSN="file:./data/k8m.db?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)"
+     SQLITE_DSN="file:./data/k8m.db?_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)"
@@
-     --sqlite-dsn="file:./data/k8m.db?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)"
+     --sqlite-dsn="file:./data/k8m.db?_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)"
🧹 Nitpick comments (3)
docs/database.md (3)

49-54: 修复裸链接并提升可读性(消除 MD034)

将裸链接改为标准 Markdown 链接,避免 lint 告警并便于点击。

-   > - 更多DSN参数,请参考https://github.com/glebarez/go-sqlite?tab=readme-ov-file#connection-string-examples
+   > - 更多 DSN 参数,请参考
+   >   [glebarez/go-sqlite - Connection string examples](https://github.com/glebarez/go-sqlite?tab=readme-ov-file#connection-string-examples)

63-63: 中文措辞微调,避免语法提示并更自然

当前“具备正确的读写权限”偶发触发语言工具提示。可微调为更自然的表述。

-1. **目录权限**: 启动前请确保数据库文件所在目录 (如 `./data`) 已存在且具备正确的读写权限。
+1. **目录权限**: 启动前请确保数据库文件所在目录(如 `./data`)已存在,且读写权限已正确配置。

56-60: 补充对网络/分布式存储的注意事项(WAL 兼容性)

在 Kubernetes/容器环境中,NFS、部分分布式/云盘对 SQLite 锁与 WAL 支持不一致,易出现锁冲突或数据损坏。建议在此处追加警示。

  为了降低多并发写入时出现 "database is locked" 的风险,K8M 已在内部启用了以下优化:
@@
  2. busy_timeout 设置为 5000ms
+ 
+ > 提示:在网络或分布式文件系统(如 NFS、部分云盘/共享存储)上,文件锁与 WAL 兼容性可能受限,仍可能出现锁冲突或不一致。
+ > 建议优先使用本地磁盘或官方明确支持 POSIX 锁的后端;对高并发写入场景,请优先考虑 MySQL/PostgreSQL。
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 765ed86 and b11f602.

📒 Files selected for processing (2)
  • docs/database.md (3 hunks)
  • pkg/flag/flag.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/flag/flag.go
🧰 Additional context used
🪛 LanguageTool
docs/database.md

[uncategorized] ~63-~63: 动词的修饰一般为‘形容词(副词)+地+动词’。您的意思是否是:正确"地"读
Context: ...*: 启动前请确保数据库文件所在目录 (如 ./data) 已存在且具备正确的读写权限。 2. 并发限制: SQLite 适合轻量级应用场景。如果您的...

(wb4)

🪛 markdownlint-cli2 (0.17.2)
docs/database.md

53-53: Bare URL used

(MD034, no-bare-urls)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
docs/database.md (1)

73-78: WAL 备份指引很到位,建议保留

已清晰给出 .backup 与 VACUUM INTO 两种安全方案,并对 cp 风险进行充分提示,符合最佳实践。

@weibaohui weibaohui merged commit b869f5f into main Aug 10, 2025
5 checks passed
@weibaohui weibaohui deleted the fix-db branch August 10, 2025 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant