idkwhoami/migration-rules
最新稳定版本:0.1.0
Composer 安装命令:
composer require idkwhoami/migration-rules
包简介
Enforce consistent Laravel migration naming and ordering via topological sort, inlining, and regeneration.
README 文档
README
A composer require --dev package that scans, sorts, inlines, and regenerates Laravel migrations to enforce consistent naming and ordering rules.
Warning: Safe to run only on undeployed apps. This tool modifies your migration files.
Requirements
- Laravel 12+ (anonymous class migration convention)
- PHP 8.2+
Installation
composer require idkwhoami/migration-rules --dev
Usage
# Preview what would change (no files written) php artisan migrate:enforce --dry-run # Apply changes php artisan migrate:enforce # Show current manifest / state php artisan migrate:enforce --status
Options
| Option | Description | Default |
|---|---|---|
--dry-run |
Preview changes without writing files | false |
--pattern |
Date prefix for filenames | 0001_01_01 |
--base-step |
Slot step for base migrations | 50 |
--pivot-step |
Slot step for pivot migrations | 25 |
--force |
Auto-resolve collisions (keep base version) | false |
--status |
Show manifest state | false |
Rules
- Filename pattern:
{prefix}_{slot}_{action}.php - Base slot step: 50 (each distinct model)
- Pivot slot step: 25
- Ordering: Topological sort by FK dependencies
- Altering migrations: Inlined into base migration (no separate altering migrations)
- down(): Omitted entirely (undeployed = no rollback needed)
FK Detection
Detects foreign keys via:
->foreignId('column')->constrained()->foreignIdFor(Model::class)->foreignUlid('column')/->foreignUuid('column')->morphs('column')/->nullableMorphs()/->ulidMorphs()/->uuidMorphs()->constrained()->onDelete(...)
External table references (tables outside database/migrations/) are skipped.
Manifest
After running, a .migration.rules file is written to your project root and added to .gitignore. This allows subsequent runs to detect drift.
License
MIT
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-28