Files
Ydisks-Xianyu-Helper/internal/db/migrations/postgres/00008_drop_dead_schema.sql
T
ChristandClaude Opus 4.8 62705c524d 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 <noreply@anthropic.com>
2026-07-06 16:51:38 +08:00

46 lines
1.7 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- +goose Up
-- +goose StatementBegin
-- 清理被 automation_rules 取代或从未使用的 schema(PostgreSQL 版)。
-- 注意:Postgres 00006 未创建 auto_create_delivery_rule/card_group_id/delivery_count
-- (SQLite 历史遗留列,00008 在 SQLite 里删除,PG 版直接没建,故此处不删)。
DROP TABLE IF EXISTS delivery_rule_variants;
DROP TABLE IF EXISTS delivery_rules;
DROP TABLE IF EXISTS captcha_codes;
-- email_verifications / ai_item_cache / risk_control_logs 在 PG 00001 未创建,
-- IF EXISTS 对不存在的表是安全的。
DROP TABLE IF EXISTS email_verifications;
DROP TABLE IF EXISTS ai_item_cache;
DROP TABLE IF EXISTS risk_control_logs;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
-- 仅重建结构,历史数据不可恢复。
CREATE TABLE IF NOT EXISTS delivery_rules (
id BIGSERIAL PRIMARY KEY,
keyword TEXT NOT NULL,
card_id BIGINT NOT NULL,
delivery_count INTEGER DEFAULT 1,
enabled INTEGER DEFAULT 1,
description TEXT,
delivery_times INTEGER DEFAULT 0,
user_id BIGINT NOT NULL DEFAULT 1,
cookie_id TEXT NOT NULL DEFAULT '',
item_id TEXT NOT NULL DEFAULT '',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS delivery_rule_variants (
id BIGSERIAL PRIMARY KEY,
rule_id BIGINT NOT NULL,
spec_name TEXT NOT NULL DEFAULT '',
spec_value TEXT NOT NULL DEFAULT '',
card_id BIGINT NOT NULL,
delivery_count INTEGER NOT NULL DEFAULT 1,
enabled INTEGER NOT NULL DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- +goose StatementEnd