f3471ae139
- 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>
21 lines
741 B
SQL
21 lines
741 B
SQL
-- 套餐与订阅
|
|
CREATE TABLE plans (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
code TEXT NOT NULL UNIQUE CHECK (code IN ('free','pro','team')),
|
|
max_devices INTEGER NOT NULL,
|
|
daily_minutes INTEGER NULL,
|
|
ad_gate INTEGER NOT NULL DEFAULT 0
|
|
);
|
|
|
|
CREATE TABLE subscriptions (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
user_id INTEGER NOT NULL,
|
|
plan_id INTEGER NOT NULL,
|
|
expires_at DATETIME NOT NULL,
|
|
source TEXT NOT NULL CHECK (source IN ('trial','code')),
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id),
|
|
FOREIGN KEY (plan_id) REFERENCES plans(id)
|
|
);
|
|
CREATE INDEX idx_subs_user_exp ON subscriptions (user_id, expires_at);
|