定制 mll-lab/laravel-conditional-migrations 二次开发

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

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

mll-lab/laravel-conditional-migrations

最新稳定版本:v3.1.1

Composer 安装命令:

composer require mll-lab/laravel-conditional-migrations

包简介

Run your Laravel migrations only when you want them to

README 文档

README

Deprecated

This package is deprecated in favor of https://github.com/mll-lab/laravel-utils/releases/tag/v4.0.0 and will no longer be updated.

CI Status codecov

Packagist Latest Stable Version GitHub license

Run migrations only if a condition is true

Based on https://github.com/onlinepets/laravel-conditional-migrations

Installation

Via composer:

composer require mll-lab/laravel-conditional-migrations

Usage

To run a migration conditionally, implement the ConditionalMigration interface and its ->shouldRun() method:

use MLL\ConditionalMigrations\Contracts\ConditionalMigration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Carbon;

class DoSomethingVeryIntensive extends Migration implements ConditionalMigration
{
    public function up() { ... }
    public function down() { ... }

    public function shouldRun(): bool
    {
        return (new Carbon('1 AM'))->lessThan(now())
            && (new Carbon('2 AM'))->greaterThan(now());
    }
}

The code snippet above will make sure the do_something_very_intensive migration will be skipped unless it is executed between 1 AM and 2 AM. This can be useful if your migration does something that should not be run during the daytime, like adding an index to a table containing lots of data.

Configuration

You can optionally publish the configuration file:

php artisan vendor:publish --tags=conditional-migrations-config

This will create the file config/conditional-migrations.php.

The always_run option allows you to overrule the conditions set in individual migrations.

'always_run' => env('APP_DEBUG', false),

You can also use a closure if you want to do more advanced calculations:

'always_run' => function (): bool {
    // calculate if migrations should always run
},

Changelog

All notable changes to this project are documented in CHANGELOG.md.

Contributing

Contributions are welcome, see CONTRIBUTING.md.

License

See LICENSE.md.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-30