---
title: "ruflo-migrations"
url: "https://claudemods.dev/zh-cn/builds/ruflo-migrations-f702c4"
source: "https://github.com/ruvnet/ruflo/tree/main/plugins/ruflo-migrations"
source_type: "github"
repo: "https://github.com/ruvnet/ruflo/tree/main/plugins/ruflo-migrations"
author: "ruvnet"
author_handle: "ruvnet"
stars: 82392
category: "安全与隐私"
categories: ["security"]
tags: ["claude-code", "database", "guard", "hooks", "migrations", "plugin", "secret-scanning", "sql-lint"]
permission_level: 2
scan_complete: true
install: "claude plugin marketplace add ruvnet/ruflo\nclaude plugin install ruflo-migrations"
added: "2026-10-05T08:14:02.472Z"
updated: "2026-11-25T06:14:05Z"
locale: "zh-cn"
content_locale: "zh-cn"
---

# ruflo-migrations

Claude Code 的数据库模式迁移管理插件，支持生成、验证、dry-run 和回滚命令，并提供只收紧的机密防护和 /migrations-mod。

## Description

ruflo-migrations 是 Claude Code 插件，用于管理数据库模式迁移：生成按顺序编号的 up/down SQL 对，验证待处理迁移的外键一致性、索引覆盖、回滚安全性、破坏性操作和命名约定，支持 dry-run 预览、应用和回滚迁移，并在 AgentDB 中追踪迁移历史。它提供基于 sonnet 的 migration-engineer 代理，以及 /migrate-create 和 /migrate-validate 技能。作为 function-hook mod，它加入默认开启的只收紧防护，拒绝包含机密或内嵌密码数据库 URL 的内存写入；提供只读的 /migrations-mod 命令，用于本地状态和 SQL 扫描；并在 .claude-flow/migrations-mod/status.json 写入状态文件。插件不联网、不启动进程，也不调用模型。使用 claude --plugin-dir plugins/ruflo-migrations 安装，并用 smoke 脚本或 claude plugin validate/test 验证。

## Install

```
claude plugin marketplace add ruvnet/ruflo
claude plugin install ruflo-migrations
```

## Original README

# ruflo-migrations

Schema migration management -- generate, validate, dry-run, and rollback database migrations.

## Overview

Generates sequentially numbered database migrations with up/down SQL pairs for rollback safety. Includes dry-run mode to preview SQL without executing, validation checks for foreign key consistency, index coverage, and naming conventions, plus full migration history tracking in AgentDB.

## Installation

```bash
claude --plugin-dir plugins/ruflo-migrations
```

## Agents

| Agent | Model | Role |
|-------|-------|------|
| `migration-engineer` | sonnet | Generate sequential migrations, create up/down pairs, dry-run validation, rollback safety checks |

## Skills

| Skill | Usage | Description |
|-------|-------|-------------|
| `migrate-create` | `/migrate-create <name>` | Create a new sequentially numbered migration with up/down SQL files |
| `migrate-validate` | `/migrate-validate` | Validate pending migrations for FK consistency, rollback safety, and best practices |

## Commands (6 subcommands)

```bash
migrate create <name>        # Create NNN_name.up.sql and NNN_name.down.sql
migrate up [--dry-run]       # Apply pending migrations (or preview SQL)
migrate down [--steps N]     # Rollback last N migrations (default: 1)
migrate status               # Show applied/pending migration status
migrate validate             # Validate pending migrations for safety
migrate history              # Show full migration execution history
```

## Validation Checks

| Check | Severity | Description |
|-------|----------|-------------|
| Foreign key targets exist | Error | Referenced table/column must exist |
| Index coverage | Warning | WHERE/JOIN columns should be indexed |
| Data type compatibility | Error | ALTER COLUMN type must be compatible |
| NOT NULL without default | Error | Adding NOT NULL column requires DEFAULT |
| Down migration completeness | Warning | Every UP needs a corresponding DOWN |
| Destructive operations | Warning | DROP TABLE/COLUMN flagged for review |
| Naming conventions | Info | Tables plural, columns snake_case |
| Idempotency | Warning | Use IF EXISTS / IF NOT EXISTS |

## Migration File Format

```
migrations/
  001_create_users.up.sql
  001_create_users.down.sql
  002_add_email_index.up.sql
  002_add_email_index.down.sql
```

## Compatibility

- **CLI:** pinned to `@claude-flow/cli` v3.6 major+minor.
- **Verification:** `bash plugins/ruflo-migrations/scripts/smoke.sh` is the contract.

## Namespace coordination

This plugin owns the `migrations` AgentDB namespace (kebab-case is implicit when the plugin name is the intent — same documented exception as `federation`). Follows the convention from [ruflo-agentdb ADR-0001 §"Namespace convention"](../ruflo-agentdb/docs/adrs/0001-agentdb-optimization.md). Reserved namespaces (`pattern`, `claude-memories`, `default`) MUST NOT be shadowed.

`migrations` is accessed via `memory_*` tools (namespace-routed). Tracks migration metadata, applied/pending status, and validation results.

> **Routing note:** Earlier versions of these skills used `agentdb_hierarchical-*` and `agentdb_pattern-store` with namespace arguments — those tool families route by tier/ReasoningBank and ignore namespace strings. ADR-0001 fixed the skills to use `memory_*` for namespaced reads/writes.

## Verification

```bash
bash plugins/ruflo-migrations/scripts/smoke.sh
# Expected: "10 passed, 0 failed"
```

## Architecture Decisions

- [`ADR-0001` — ruflo-migrations plugin contract (namespace-routing fix, smoke as contract)](./docs/adrs/0001-migrations-contract.md)

## Related Plugins

- `ruflo-agentdb` — namespace convention owner; defines the routing rules ADR-0001 fixes a violation of
- `ruflo-adr` -- Document schema change decisions as ADRs
- `ruflo-ddd` -- Align migration boundaries with aggregate roots
- `ruflo-observability` -- Track migration execution duration and failure rates

## License

MIT

## As a mod

Function-hook mod (ADR-445 pattern, `hooks/register.ts`). It adds, with no network, no process spawning and no model call:

- **Guard** (tighten-only, default on): refuses a memory write (memory_store, agentdb_*store/batch) that holds a secret or a database URL with an inline password. The deny reason names the rule, never the value.
- **`/migrations-mod`**: local `status` and `scan <text>` (secret check, same rules as the guard); `/migrations-mod scan <sql>` lints SQL for DROP/TRUNCATE/DROP COLUMN/DELETE-without-WHERE (read-only).
- **Status file** `.claude-flow/migrations-mod/status.json` (`{version:1, updatedMs, guard, checked, blocked, ...}`), written at session start and when counters change.

Per-prompt context is deliberately not added: this plugin has nothing worth attaching to every prompt.

| Option | Default | Effect |
|---|---|---|
| `guard` | `on` | refuse the calls above |

Test: `claude plugin validate plugins/ruflo-migrations`, `claude plugin test plugins/ruflo-migrations`, `bash plugins/ruflo-migrations/scripts/smoke.sh`.
