fr3on/laravel-forecast 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

fr3on/laravel-forecast

Composer 安装命令:

composer require fr3on/laravel-forecast

包简介

Preview pending migration impact — row counts, lock estimates, and risk ratings — before you run migrate.

README 文档

README

GitHub Tests Action Status GitHub Code Style Action Status PHP Version Laravel Version License

php artisan migrate:forecast — see exactly what your pending migrations will do, how many rows are at risk, and how long the table lock might last, before you type migrate.

The problem

migrate --pretend gives you raw SQL. The confirmation prompt gives you nothing. Neither tells you:

  • "This ALTER TABLE touches a 12M-row table — expect ~8 minutes of locking"
  • "This DROP COLUMN still has data in 4,200 rows"
  • "This NOT NULL column has no DEFAULT — it will fail on existing rows"

Teams find this out the hard way, mid-deploy, at 2am.

Installation

composer require fr3on/laravel-forecast

The service provider is auto-discovered. No configuration is required to start.

Optionally publish the config:

php artisan vendor:publish --tag=forecast-config

Usage

php artisan migrate:forecast

Example output:

  Laravel Forecast  |  3 pending migrations

  2024_08_01_add_status_to_orders
  ┌──────────────────────────────────────┬─────────┬──────────┬──────────────────┐
  │ Operation                            │ Risk    │ Rows     │ Est. lock        │
  ├──────────────────────────────────────┼─────────┼──────────┼──────────────────┤
  │ ADD COLUMN orders                    │ SAFE    │ 4.2M     │ < 1s (online)    │
  └──────────────────────────────────────┴─────────┴──────────┴──────────────────┘

  2024_08_02_drop_legacy_payments_table
  ┌──────────────────────────────────────┬─────────┬──────────┬──────────────────┐
  │ Operation                            │ Risk    │ Rows     │ Est. lock        │
  ├──────────────────────────────────────┼─────────┼──────────┼──────────────────┤
  │ DROP TABLE legacy_payments           │ DANGER  │ 38,441   │ instant          │
  └──────────────────────────────────────┴─────────┴──────────┴──────────────────┘
  ⚠  Entire table and all its data will be permanently deleted.
  ⚠  38,441 rows will be permanently deleted.

  2024_08_03_index_orders_user_id
  ┌──────────────────────────────────────┬─────────┬──────────┬──────────────────┐
  │ Operation                            │ Risk    │ Rows     │ Est. lock        │
  ├──────────────────────────────────────┼─────────┼──────────┼──────────────────┤
  │ CREATE INDEX orders                  │ CAUTION │ 4.2M     │ ~42s (estimated) │
  └──────────────────────────────────────┴─────────┴──────────┴──────────────────┘
  ℹ  May lock the table during index creation on older engines.
     Consider ALGORITHM=INPLACE, LOCK=NONE for zero-downtime.

  SAFE: 1   CAUTION: 1   DANGER: 1
  Run with --ci to exit code 1 on any DANGER operation.

CI / CD integration

php artisan migrate:forecast --ci
# exits 1 if any DANGER operation is detected — blocks the pipeline automatically

How it works

  1. Collects pending migrations — reads the migrations repository to find which files haven't been run yet.
  2. Captures SQL without executing — uses Laravel's built-in connection->pretend() to get the exact SQL each migration would run.
  3. Classifies each statement — regex-based SQL analysis extracts the operation type and table name.
  4. Queries row counts — runs SELECT COUNT(*) FROM <table> against your live database.
  5. Estimates lock time — applies heuristics based on operation type and row count.

No AST parsing. No reflection hacks. Just SQL string analysis + a COUNT query.

Risk classification

Operation Risk Reason
CREATE TABLE, ADD COLUMN with DEFAULT or nullable SAFE Additive; online DDL on MySQL 8+
ADD COLUMN NOT NULL without DEFAULT DANGER Will fail on non-empty tables
DROP TABLE, DROP COLUMN DANGER Irreversible data loss
CREATE INDEX CAUTION May lock table depending on engine version
RENAME COLUMN / RENAME TABLE CAUTION May break queries and views
ALTER COLUMN (type/constraint change) CAUTION Risk of data truncation
NOT NULL constraint on existing column DANGER Fails if any row contains NULL

Configuration

After publishing config/forecast.php you can tune:

return [
    // Row count above which extra warnings are shown
    'large_table_threshold'  => env('FORECAST_LARGE_TABLE_THRESHOLD', 1_000_000),
    'medium_table_threshold' => env('FORECAST_MEDIUM_TABLE_THRESHOLD', 100_000),

    // Lock-time heuristics (milliseconds per 1,000 rows)
    'ms_per_thousand_rows' => [
        'drop_column'  => 10,
        'create_index' => 10,
        'alter_column' => 15,
        'add_column'   => 5,
    ],

    // Extra migration paths to scan (in addition to database/migrations)
    'migration_paths' => [],
];

What it is NOT

  • Not a replacement for migrate — it only informs before you commit.
  • Not migrate --pretend — that shows SQL; this shows impact.
  • Not enlightn — that checks code security; this checks schema risk.
  • No SaaS, no agents, no database tables. Install and run immediately.

License

MIT

fr3on/laravel-forecast 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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