feat(database): support configurable SSL mode for PostgreSQL and MySQL

Add ssl_mode configuration option to allow users to customize SSL/TLS
policy for database connections instead of hardcoding sslmode=disable
for PostgreSQL and having no TLS support for MySQL.

Changes:
- database.Config, DatabaseConfig: add SSLMode field
- PostgreSQL DSN: replace hardcoded sslmode=disable with configurable
value
- MySQL DSN: append &tls=<SSLMode> parameter when SSLMode is set
- Full config pipeline: INI/env -> DatabaseConfig -> Config -> DSN ->
subprocess
- New env var BH_DB_SSL_MODE and ini key [database] ssl_mode
- Updated config example and documentation
This commit is contained in:
little-sparkleeesss
2026-06-13 23:19:03 +08:00
parent 0533fe6c9c
commit ae273d5b92
7 changed files with 46 additions and 11 deletions
+1
View File
@@ -22,6 +22,7 @@
| `BH_DB_PATH` | database.path | SQLite 物理文件存储路径 | ./data/baihu.db |
| `BH_DB_DSN` | database.dsn | 数据库 DSN (仅 mysql/postgres, 优先级高。**需对应设置 type**) | - |
| `BH_DB_TABLE_PREFIX` | database.table_prefix | 数据库表前缀 | baihu_ |
| `BH_DB_SSL_MODE` | database.ssl_mode | SSL 模式: postgres 支持 disable/require/verify-ca/verify-full; mysql 支持 true/skip-verify | - |
| `BAIHU_SECRET_KEY` | - | 系统加密秘钥,用于机密变量功能(**注:仅支持环境变量设置,不支持配置文件**) | - |
---