定制 idkwhoami/migration-rules 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固