feat(server/db): 数据层多库支持(1/4)— 连接分派 + 双方言迁移管线
- config 增 DB_DRIVER(mysql 默认 | sqlite);DSN 对 sqlite 为文件路径
- db.OpenDriver 按驱动分派:sqlite 用 modernc(纯 Go 免 CGO)+ WAL/
busy_timeout/foreign_keys/_txlock=immediate;mysql 路径不变
- store.Open 分派;mysql 保留 UTC/collation 断言,sqlite 跳过
- 迁移拆 migrations/{mysql,sqlite}/ 双套,embed 双 FS,migrate 按驱动选源
与 golang-migrate 驱动;修复 m.Close() 误关调用方 *sql.DB 的坑
- cmd/migrate 串入 DB_DRIVER;集成测试 MigrateUp 签名更新
- 新增 SQLite 时间往返 smoke 测试与端到端迁移测试(免 docker)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
// Package migrations provides the embedded SQL migration files for golang-migrate.
|
||||
// Files are named in the golang-migrate convention:
|
||||
// Files are named in the golang-migrate convention, under one subdir per dialect:
|
||||
//
|
||||
// {version}_{title}.up.sql
|
||||
// {version}_{title}.down.sql
|
||||
// mysql/{version}_{title}.{up,down}.sql
|
||||
// sqlite/{version}_{title}.{up,down}.sql
|
||||
//
|
||||
// The FS is consumed by internal/store.MigrateUp / MigrateDown.
|
||||
// The two FS values are consumed by internal/store.MigrateUp / MigrateDown,
|
||||
// selected by the configured DB driver. Version numbers are kept aligned across
|
||||
// dialects so schema evolution adds one file to each set.
|
||||
package migrations
|
||||
|
||||
import "embed"
|
||||
|
||||
// FS contains all *.sql files in this directory, embedded at compile time.
|
||||
// MySQLFS holds the MySQL-dialect migrations.
|
||||
//
|
||||
//go:embed *.sql
|
||||
var FS embed.FS
|
||||
//go:embed mysql/*.sql
|
||||
var MySQLFS embed.FS
|
||||
|
||||
// SQLiteFS holds the SQLite-dialect migrations.
|
||||
//
|
||||
//go:embed sqlite/*.sql
|
||||
var SQLiteFS embed.FS
|
||||
|
||||
Reference in New Issue
Block a user