ChristandClaude Opus 4.8 36a7f74154 refactor(db): 阶段B+C - MySQL/Postgres migration + 方言适配器
migration
- migrations/mysql/ 8 个文件:BIGINT AUTO_INCREMENT、VARCHAR 主键、
  TINYINT(1) 布尔、INSERT IGNORE、ON DUPLICATE KEY UPDATE
- migrations/postgres/ 8 个文件:BIGSERIAL、BOOLEAN、ON CONFLICT DO UPDATE
- 跳过 SQLite 历史遗留列(auto_create_delivery_rule 等)在 mysql/pg 00006
  不创建,00008 不删除

方言适配器 (internal/db/dialect.go)
- DialectUpsert: SQLite/PG 用 ON CONFLICT DO UPDATE + EXCLUDED.col;
  MySQL 用 ON DUPLICATE KEY UPDATE + VALUES(col)
- DialectInsertIgnore + DialectInsertIgnorePrefix: MySQL INSERT IGNORE;
  SQLite/PG ON CONFLICT DO NOTHING
- DialectQuote: MySQL/SQLite 反引号,Postgres 双引号(处理 key 等保留字列名)

业务 SQL 改造(16 处 upsert)
- db: cookies/extras(系统设置/商品信息/通知绑定)/orders/reply/automation
  全部改用方言适配器;item_replay Set 改 DELETE+INSERT(无自然唯一键)
- server: notification_handlers/settings_handlers/default_reply_handlers
  的 ON CONFLICT/INSERT OR REPLACE 改用 db.DialectUpsert
- 各 repository struct 加 Dialect 字段,NewStore 注入

验证:SQLite 全测试通过(回归),MySQL/PG migration 已就位待真实实例验证

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 12:58:23 +08:00

闲鱼管家

这是当前活跃版本:Go 后端 + React 前端。后续功能迭代均在此目录进行:

xianyu-go/
  cmd/server/              Go 服务入口
  internal/                Go 后端代码
  frontend/                当前活跃 React 前端源码
  internal/webui/static/   前端构建产物,Go 会内置并提供给浏览器

首次运行

1. 安装前端依赖并构建

cd /Users/christ/Workspace/git/xianyu/xianyu-go/frontend
npm install
npm run build

构建产物会写入:

xianyu-go/internal/webui/static/

2. 初始化管理员

cd /Users/christ/Workspace/git/xianyu/xianyu-go
go run ./cmd/init-admin -db data/xianyu_data.db

也可以通过服务入口非交互初始化:

go run ./cmd/server \
  -init-admin \
  -db data/xianyu_data.db \
  -admin-password '你的密码'

3. 启动服务

cd /Users/christ/Workspace/git/xianyu/xianyu-go
go run ./cmd/server -db data/xianyu_data.db -addr :8080

浏览器访问:

http://localhost:8080

不传 -web 时,Go 会使用 internal/webui/static 中的内置前端资源。

开发模式

后端:

cd /Users/christ/Workspace/git/xianyu/xianyu-go
go run ./cmd/server -db data/xianyu_data.db -addr :8080

前端开发服务器:

cd /Users/christ/Workspace/git/xianyu/xianyu-go/frontend
npm run dev

访问:

http://localhost:3000

Vite 会把 API 请求代理到 http://localhost:8080。

编译运行

cd /Users/christ/Workspace/git/xianyu/xianyu-go
go build -o xianyu-server ./cmd/server
./xianyu-server -db data/xianyu_data.db -addr :8080

如果要使用外部前端目录,也可以传:

./xianyu-server -db data/xianyu_data.db -addr :8080 -web /path/to/static

Docker 部署注意

批量铺货会用到上传目录。容器部署时建议挂载持久化数据:

-v ./data:/app/data

并设置:

XIANYU_UPLOAD_DIR=/app/data/uploads

数据库建议放在:

/app/data/xianyu_data.db

常用参数

参数 说明
-db SQLite 数据库路径,默认 data/xianyu_data.db
-addr HTTP 监听地址,默认 :8080
-web 外部前端静态资源目录;不传则用内置前端
-init-admin 初始化或重置管理员后退出
-admin-email 初始化管理员邮箱
-admin-password 初始化管理员密码
-no-browser 禁用内置浏览器自动化
-secure HTTPS 模式,Cookie 加 Secure
-v 调试日志

验证

cd /Users/christ/Workspace/git/xianyu/xianyu-go
go test ./...

cd /Users/christ/Workspace/git/xianyu/xianyu-go/frontend
npm run build
S
Description
闲鱼多账号自动发货、消息回复系统——基于 Go 与 React 构建
Readme Apache-2.0
17 MiB
0 Stars 1 Watchers 0 Forks
Languages
Go 74.2%
TypeScript 23.4%
JavaScript 1.1%
Inno Setup 0.5%
Shell 0.4%
Other 0.3%