fix(db): 真实容器验证 Postgres/MySQL 方言修复

Docker 起 mysql:8 / postgres:16 实跑迁移+核心 CRUD,发现并修复三处阻断问题:

- pgx 不支持 ? 占位符:新增 pgx_compat driver 包裹 pgx stdlib,把 ? 重写为 $N
  (internal/db/pgx_compat.go),driverPgx 指向它;全仓库 ? 写法零改动。
- pgx 对 BOOLEAN 严格按 bool 读写,与 int/boolToInt 写法不兼容:Postgres
  migration 的 BOOLEAN 列改 INTEGER 0/1,与 SQLite/MySQL 对齐 (00001/00004/00008)。
- pgx 不支持 Result.LastInsertId:新增 insertReturningID helper,Postgres 走
  INSERT ... RETURNING id,SQLite/MySQL 走 LastInsertId (Cards/Keywords/
  Notifications/Automation 的 INSERT 路径)。

附带 MySQL 部署加固:parseDBURL 自动补 multiStatements=true(缺失会静默只执行
首条迁移语句);base_url TEXT→VARCHAR(512)(strict mode 拒绝 TEXT+DEFAULT)。
新增 cmd/dbverify 三库迁移+核心 CRUD 烟囱测试工具。

验证:SQLite/MySQL/Postgres 三库 9 步 CRUD 全通过;go test ./... 与 go vet 通过。

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
ChristandClaude Opus 4.8 committed 2026-07-06 16:51:38 +08:00
1 parent fb83aacb8b
commit 62705c524d
13 files changed
+449 -62

No files matched your search

@@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS delivery_rules (
keyword TEXT NOT NULL,
card_id BIGINT NOT NULL,
delivery_count INTEGER DEFAULT 1,
enabled BOOLEAN DEFAULT TRUE,
enabled INTEGER DEFAULT 1,
description TEXT,
delivery_times INTEGER DEFAULT 0,
user_id BIGINT NOT NULL DEFAULT 1,
@@ -38,7 +38,7 @@ CREATE TABLE IF NOT EXISTS delivery_rule_variants (
spec_value TEXT NOT NULL DEFAULT '',
card_id BIGINT NOT NULL,
delivery_count INTEGER NOT NULL DEFAULT 1,
enabled BOOLEAN NOT NULL DEFAULT TRUE,
enabled INTEGER NOT NULL DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);