承接 grazulex/laravel-strongmigrations 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

grazulex/laravel-strongmigrations

Composer 安装命令:

composer require grazulex/laravel-strongmigrations

包简介

Detect dangerous migrations before they break production. Catch unsafe operations, get guided alternatives, and keep your database safe.

README 文档

README

Tests Code Quality Latest Version on Packagist PHP Version License

Detect dangerous migrations before they hit production. Inspired by the Rails strong_migrations gem.

Laravel Strong Migrations analyzes your migration files using AST parsing (nikic/php-parser) and warns you about operations that could cause downtime, data loss, or lock contention on large tables.

Features

  • 16+ built-in rules covering common dangerous operations
  • Database-aware — version-specific rules for MySQL, MariaDB, and PostgreSQL
  • Two modesblock (prevents migration) or warn (displays warning)
  • AST-based analysis — no migration execution required
  • CI/CD ready — JSON and GitHub Actions output formats
  • Customizable — disable rules, add custom checks, bypass with safetyAssured
  • Multilingual — English and French translations included

Installation

composer require grazulex/laravel-strongmigrations

Publish the configuration:

php artisan strong-migrations:install

How It Works

Strong Migrations listens to Laravel's MigrationStarted event. When you run php artisan migrate, each migration is parsed and checked against the rule engine before it executes.

If a dangerous operation is detected:

  • In block mode (default): an exception is thrown with a safe alternative
  • In warn mode: a warning is displayed, migration proceeds

Rules

Common Rules (All Databases)

Rule ID Detects Severity
remove_column Dropping a column High
rename_column Renaming a column High
rename_table Renaming a table High
create_table_force dropIfExists before create High
backfill_in_migration Data + schema changes in same migration Medium
add_auto_increment Adding auto-increment columns Medium
raw_sql Raw SQL statements Warning
wide_index Index with > 3 columns Low

MySQL / MariaDB Rules

Rule ID Detects Severity
add_column_with_default Adding NOT NULL column with default (< MySQL 8.0.12 / MariaDB 10.3.2) High
change_column_type Changing column type (table rewrite) High
set_not_null_mysql Setting NOT NULL constraint Medium

PostgreSQL Rules

Rule ID Detects Severity
add_index_non_concurrent Adding index without CONCURRENTLY High
add_foreign_key Adding foreign key (locks both tables) High
add_check_constraint Adding check constraint Medium
add_unique_constraint Adding unique constraint Medium
json_column Using json instead of jsonb Low
set_not_null_pgsql Setting NOT NULL (full table scan) Medium

Usage

Automatic Protection

Once installed, Strong Migrations automatically checks all migrations during php artisan migrate:

$ php artisan migrate

Dangerous operation detected in migration: 2025_01_15_000001_drop_email.php

[remove_column] Removing column `email` that is used by the application
will cause errors until application servers are restarted.

Safe alternative:

Step 1 - Ignore the column in your Eloquent model:
    protected static array $ignoredColumns = ['email'];

Step 2 - Deploy the code.

Step 3 - Create a migration that drops the column, wrapped in:
    StrongMigrations::safetyAssured(function () { ... });

Artisan Commands

Check all migrations

# Text output (default)
php artisan migrate:check

# JSON output (for CI/CD)
php artisan migrate:check --format=json

# GitHub Actions annotations
php artisan migrate:check --format=github

# Custom path
php artisan migrate:check --path=database/migrations

Analyze a specific migration

php artisan migrate:analyze 2025_01_15_000001_drop_email.php

Bypassing Checks

When you've verified a migration is safe, wrap it in safetyAssured:

use Grazulex\StrongMigrations\StrongMigrations;

return new class extends Migration
{
    public function up(): void
    {
        StrongMigrations::safetyAssured(function () {
            Schema::table('users', function (Blueprint $table) {
                $table->dropColumn('legacy_field');
            });
        });
    }
};

Custom Checks

Add custom rules in a service provider:

use Grazulex\StrongMigrations\StrongMigrations;

StrongMigrations::addCheck(function (Operation $operation, DatabaseContext $context) {
    if ($operation->type === OperationType::AddColumn && $operation->column === 'metadata') {
        StrongMigrations::stop('Use `data` instead of `metadata` for consistency.');
    }
});

Custom Messages

Override the default message for the next violation:

StrongMigrations::setMessage('This migration has been reviewed and approved by the DBA team.');

Configuration

// config/strong-migrations.php
return [
    // Enable/disable the package
    'enabled' => env('STRONG_MIGRATIONS_ENABLED', true),

    // 'block' or 'warn'
    'mode' => env('STRONG_MIGRATIONS_MODE', 'block'),

    // Override auto-detected database driver
    'database_driver' => env('STRONG_MIGRATIONS_DRIVER'),

    // Override auto-detected database version
    'database_version' => env('STRONG_MIGRATIONS_VERSION'),

    // Skip migrations before this timestamp (format: YYYY_MM_DD_HHMMSS)
    'start_after' => null,

    // Disable specific rules by ID
    'disabled_checks' => [
        // 'remove_column',
        // 'raw_sql',
    ],
];

CI/CD Integration

GitHub Actions

- name: Check migrations
  run: php artisan migrate:check --format=github

This outputs annotations that appear directly on pull request diffs.

Generic CI

- name: Check migrations
  run: php artisan migrate:check --format=json

Returns exit code 1 if any violations are found.

Supported Databases

Database Version Notes
MySQL 5.7+ Version-aware rules (8.0.12+ allows instant ADD COLUMN)
MariaDB 10.2+ Version-aware rules (10.3.2+ allows instant ADD COLUMN)
PostgreSQL 12+ CONCURRENTLY, foreign key, and constraint rules
SQLite Any Reduced rule set (safe for development)

Requirements

  • PHP 8.2+
  • Laravel 11.x or 12.x

Testing

composer test

Code Quality

composer phpstan    # PHPStan level 8
composer pint       # Laravel Pint

Contributing

Please see CONTRIBUTING.md for details.

Security

If you discover a security vulnerability, please see SECURITY.md.

License

The MIT License (MIT). Please see LICENSE.md for more information.

grazulex/laravel-strongmigrations 适用场景与选型建议

grazulex/laravel-strongmigrations 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「migrations」 「laravel」 「safety」 「pest」 「php8」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 grazulex/laravel-strongmigrations 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 grazulex/laravel-strongmigrations 我们能提供哪些服务?
定制开发 / 二次开发

基于 grazulex/laravel-strongmigrations 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 39
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-25