定制 ziming/laravel-specific-migrate-fresh 二次开发

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

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

ziming/laravel-specific-migrate-fresh

最新稳定版本:0.2

Composer 安装命令:

composer require ziming/laravel-specific-migrate-fresh

包简介

Migrate Fresh for Specific Tables Only

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Want php artisan migrate:fresh but not drop all the tables? This is for you.

Support me

Donations are welcomed.

Installation

You can install the package via composer:

composer require ziming/laravel-specific-migrate-fresh

You can publish the config file with:

php artisan vendor:publish --tag="specific-migrate-fresh-config"

This is the contents of the published config file:

return [

    /*
     * There are 2 modes 'exclude' and 'include'.
     *
     * 'exclude' mode will drop all tables except the tables you specified in the 'excluded_tables' array.
     * 'include' mode will drop only the tables you specified in the 'included_tables' array.
     */
    'mode' => env('SPECIFIC_MIGRATE_FRESH_MODE', 'exclude'),

    /*
     * This will be used if mode is 'exclude'.
     *
     * If mode is 'exclude', the database tables in this array will be excluded
     * from getting dropped.
     */
    'excluded_tables' => [
        //
    ],

    /*
     * This will be used if mode is 'include'.
     *
     * If mode is 'include', only the database tables in this array will be dropped
     */
    'included_tables' => [
        //
    ],
];

Usage

Go to the config file, choose your preferred mode ('exclude' or 'include').

Fill in the relevant array ('excluded_tables' or 'included_tables').

Go to your migrations and for the tables you do not want to drop, in the up() method, add in a conditional check to skip the migration if the table still exists. You need to do this so that php artisan migrate will not throw an error about the table or column already exist later.

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('some_giant_table_i_do_not_want_to_drop')) {
            return;
        }

        Schema::create('some_giant_table_i_do_not_want_to_drop', function (Blueprint $table) {
            $table->id();
            // Other columns
        }
}

And call the command below. The --seed option is optional.

php artisan migrate:specific-fresh --seed

The end of this command simply just call the php artisan migrate --seed command at the end.

If you do not want to call your DatabaseSeeder. Leave out --seed from your command.

php artisan migrate:specific-fresh

Testing

PRs are welcomed on this

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-27