spark-server/.cursor/skills/spark-im-v3/mysql.md
zhr 8870c59e2d docs(cursor): 优化 spark-im-v3 skill 与 Agent 说明
新增 mysql.md(t_ 表名与 migrate 流程),补全 /v1/music·square 与 admin 路由说明;description 与 AGENTS/rules 对齐 make test→lint 与 deploy 门禁,减少与 verify-before-done 重复。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-24 11:09:15 +08:00

1.4 KiB

MySQL: t_ tables, migrations, GORM

Table names

All application tables use the t_ prefix (t_users, t_messages, t_music_tracks, …).

Layer Rule
SQL migrations CREATE TABLE t_*, RENAME TABLE … TO t_*
GORM func (Row) TableName() string { return "t_…" } on every row struct
Raw SQL in logic/model Use t_* names; do not reference unprefixed legacy names

Legacy DBs: migrations/0000_table_prefix.sql renames old tables before 0001+ (no-op if already prefixed). New environments rely on CREATE t_* in later files.

Migrations workflow

  • Files live in migrations/*.sql; cmd/migrate replays every file on each run (no version table). Order matters: 0000 before creates.
  • Every new/changed migration: run in the agent session:
go run ./cmd/migrate -config configs/config.yaml

Do not tell the user to apply SQL manually on deploy unless they asked for ops-only steps.

Schema documentation

  • Table-level and column-level COMMENT in SQL; mirror intent in GORM struct tags where the team already uses comments.
  • Closed numeric/string sets: entity enum + OpenAPI $ref (enums.md), not ad hoc magic numbers in SQL.

Logic tests vs DB

  • internal/module/*/logic tests use stubs/fakes; they must not require MySQL.
  • Model/repo integration belongs in transport tests or dedicated DB tests if added later.