migration

A set of rules for writing database migration scripts, which are files that change a database's structure over time. It covers MySQL 8 tables, columns, filenames, locations, and required fields.

In plain words
What is it for?
Use it when creating or reviewing migration SQL, including filenames, table constraints, enum columns, IDs, and timestamp fields.
Why use it?
It gives developers consistent conventions for database changes and helps prevent invalid or hard-to-track migrations.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/sunmh207/entire-dashboard/migration
Clone the repo
git clone --depth 1 https://github.com/sunmh207/entire-dashboard

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 780 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00780
Opus 5 $0.00000 $0.00390
Sonnet 5 $0.00000 $0.00156
Haiku 4.5 $0.00000 $0.00078

Measured yesterday against content hash bacefad4bac4, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

migration scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

server/.cursor/rules/migration.mdc · 90 lines

What it actually says

Migration 数据库迁移脚本规范

1. 目录结构

  • 业务代码的 Migration 脚本放置在:src/main/resources/db/migration/ 目录下。
  • 单元测试的 Migration 脚本放置在:src/test/resources/testdb/migration/ 目录下。

2. 脚本文件命名规范

  • 命名格式:V{YYYYMMDDHHIISS}__{Name}.sql
    • YYYYMMDDHHIISS:当前时间戳,精确到秒,应使用系统工具获取当前时间戳。YYYY表示年份,MM表示月份,DD表示日期,HH表示小时(24 小时制),II表示分钟,SS表示秒。
    • {Name}:迁移名称,使用驼峰,首字母大写,例如:CreateProjectTable
  • 命名:假设当前时间为2025-11-15 14:52:33,那么可以命名为:V20251115145233__CreateProjectTable.sql

3. 数据库与字符集规范

  • 当前项目数据库版本:MySQL 8

4. 表、字段书写规范

4.1. 非空约束

  • 业务规则不允许为空的字段须声明为:NOT NULL

4.2. 正整数约束

  • 业务规则不允许为负数的整型字段必须声明为:INTEGER。

4.3. 枚举字段

  • 对应 Entity 中的 Enum 字段,数据库中需定义为:VARCHAR 类型,并添加注释说明可选枚举值,枚举值大写,用下划线分隔多个单词。

4.4. 非必填 ID 字段

  • 非必填 ID 字段的默认值应为 NULL,不要使用 0

5. 必要公共字段

每张表必须包含如下字段:

5.1. 主键 ID

id INTEGER NOT NULL

5.2. 创建时间

created_at INTEGER NOT NULL

5.3. 更新时间

updated_at INTEGER NOT NULL

5.4. 字段顺序:

  1. 第 1 个字段必须是 "id";
  2. 最后两个字段必须是 "created_at"、"updated_at";
  3. 其他业务字段置于中间。

7. 表创建模板(推荐示例)

CREATE TABLE "user" (
    "id" INTEGER NOT NULL PRIMARY KEY,
    "username" VARCHAR(64) NOT NULL,
    "email" VARCHAR(128) NOT NULL,
    "status" VARCHAR(32) NOT NULL,
    "created_at" INTEGER NOT NULL,
    "updated_at" INTEGER NOT NULL,
    UNIQUE ("email") -- 唯一约束
);

8. Migration 脚本编写规范

  • 一个 Migration 脚本只做一件事(单一职责原则)。
  • 禁止在 Migration 中写依赖业务逻辑的数据,例如动态 ID、动态时间等。
  • 变更表结构必须使用 ALTER TABLE,不得使用 DROP + CREATE 替代。
  • 如需删除字段,优先采用软方式(废弃字段),再评估是否物理删除。
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 90 lines · 780 tokens per session scan A bacefad4bac4

Subscribe to this mod's changes

migration is a cursor rule published in the GitHub repository sunmh207/entire-dashboard (24 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 780 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.