- db.Open 改为接受 URL(sqlite:// mysql:// postgres://),返回 (db, dialect, err) - 向后兼容:不含 scheme 的路径仍按 SQLite 文件处理 - migration 移到 migrations/sqlite/ 子目录,embed 包含三个方言目录 - Migrate 按方言选择子目录 + goose dialect - Store 加 Dialect 字段,NewStore(db, dialect) - cmd/server 加 -db-url 和 DATABASE_URL 环境变量(优先级:env > -db-url > -db) - cmd/init-admin 同步支持 URL - 新增依赖 pgx/v5、go-sql-driver/mysql - mysql/postgres migration 目录暂为 SQLite 副本占位,阶段B/C 替换 - 所有测试调用方更新为新签名 验证:现有测试全过(SQLite 回归),SQLite 行为不变 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
23 lines
810 B
SQL
23 lines
810 B
SQL
-- +goose Up
|
|
-- +goose StatementBegin
|
|
CREATE TABLE IF NOT EXISTS ws_messages (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
cookie_id TEXT NOT NULL,
|
|
direction TEXT NOT NULL DEFAULT 'in',
|
|
raw_text TEXT NOT NULL DEFAULT '',
|
|
parsed_json TEXT NOT NULL DEFAULT '',
|
|
message_kind TEXT NOT NULL DEFAULT '',
|
|
parse_status TEXT NOT NULL DEFAULT 'raw',
|
|
error TEXT NOT NULL DEFAULT '',
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (cookie_id) REFERENCES cookies(id) ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_ws_messages_cookie_id_created_at ON ws_messages(cookie_id, created_at DESC);
|
|
-- +goose StatementEnd
|
|
|
|
-- +goose Down
|
|
-- +goose StatementBegin
|
|
DROP INDEX IF EXISTS idx_ws_messages_cookie_id_created_at;
|
|
DROP TABLE IF EXISTS ws_messages;
|
|
-- +goose StatementEnd
|