caloskao/migrate-specific
Composer 安装命令:
composer require caloskao/migrate-specific
包简介
Easily perform database migrations of specific migration files in the Laravel framework.
README 文档
README
MigrateSpecific is a Laravel framework CLI extension command that helps you easily perform database migrations of specific migration files.
Requirement
laravel/framework v5.7 or later.
Installation
Using composer to install, run this command in your project root directory:
composer require caloskao/migrate-specific
Now, run php artisan , you can see migrate:specific in the migrate section:
migrate
migrate:fresh Drop all tables and re-run all migrations
migrate:install Create the migration repository
migrate:refresh Reset and re-run all migrations
migrate:rollback Rollback the last database migration
migrate:specific Migrate, refresh, reset or rollback for specific migration files.
migrate:status Show the status of each migration
Upgrade from version 1.x
In version 1.x, you may have already registered the command at app / Console / Kernel.php:
protected $commands = [
\CalosKao\MigrateSpecific::class
];
MigrateSpecific uses laravel package discovery to automatically load commands after version 2.0, so you don't need to manually register the commands, but if you have manual registration, you may encounter a class not found exception when you run the application.
To fix this, just remove the class register.
protected $commands = [
\CalosKao\MigrateSpecific::class // remove this line.
];
Usage
You can run php artisan help migrate:specific to check command usage:
Description:
Migrate, rollback or refresh for specific migration files.
Usage:
migrate:specific [options] [--] [<files>...]
Arguments:
files File or directory path, support multiple file (Sperate by space) [default: "database/migrations"]
Options:
-p, --pretend Dump the SQL queries that would be run
-f, --skip-foreign-key-checks Set FOREIGN_KEY_CHECKS=0 before migrate
-k, --keep-batch Keep batch number. (Only works in refresh mode)
-m, --mode[=MODE] Set migrate execution mode, supported mode have: default, rollback, refresh [default: "default"]
-y, --assume-yes Automatically assumes "yes" to run commands in non-interactive mode. This option is automatically enabled if you use the option "-n" or "-q"
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Examples
Migrate single file or directory:
php artisan migrate:specific <path>
Migrate mutiple migrations on different paths:
php artisan migrate:specific <path 1> <path 2> <path 3> ...
Output is like below:
The following migration files will be migrated:
2014_10_12_000000_create_users_table.php
2018_07_31_174401_create_jobs_table.php
2018_07_31_185911_create_failed_jobs_table.php
Is this correct? (yes/no) [no]:
> yes
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table
Migrating: 2018_07_31_174401_create_jobs_table
Migrated: 2018_07_31_174401_create_jobs_table
Migrating: 2018_07_31_185911_create_failed_jobs_table
Migrated: 2018_07_31_185911_create_failed_jobs_table
Migrate mode
Use option -m or --mode to run migrate:refresh or migrate:rollback for specific migrations.
# Rollback mode
php artisan migrate:specific -m rollback <path>
# Refresh mode
php artisan migrate:specific -m refresh <path>
Keep batch number in refresh mode
Use option -k or --keep-batch to keep migration batch.
Before migrate:
| Ran? | Migration | Batch |
|---|---|---|
| Yes | 2019_02_14_011711_create_password_resets_table | 1 |
| Yes | 2019_02_14_011711_create_users_table | 2 |
php artisan migrate:specific -m refresh -k database/migrations/2019_02_14_011711_create_password_resets_table.php
Run php artisan migrate:status after migrate, you can see the migration 2019_02_14_011711_create_password_resets_table batch number will not be changed.
Skip foreign key checks
If your pattern has foreign key constraints, sometimes you might get errors, for example on MySQL or MariaDB:
Rolling back: 2019_02_14_011711_create_users_table
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table `users`)
Use option -f of --skip-foreign-key-checks to execute database statement SET FOREIGN_KEY_CHECKS=0 before migrate.
Note: A good practice is to rollback related foreign key migration at the same time, otherwise you may still get other errors, such as SQL Error 1091.
Rolling back: 2019_02_14_011711_create_users_table
SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP FOREIGN KEY `fk_projects_users_1`; check that it exists (SQL: alter table `reports` drop foreign key `fk_projects_users_1`)
Skip confirmation
Sometimes we need to perform a database migration many times, or we need to deploy it into an automated process. At this time, we can use the option -y to directly perform database migration without confirmation.
php artisan migrate:specific -y <path>
Note:
- If you call the option
-nor-q, MigrateSpecific will be automatically skip confirmation. - If you are not working in the above situations, we recommend that you do not perform a database migration in non-interactive mode to avoid accidental data loss.
License
The MigrateSpecific extension is open-sourced software licensed under the MIT license.
caloskao/migrate-specific 适用场景与选型建议
caloskao/migrate-specific 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.54k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2018 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「mysql」 「laravel」 「migrate」 「eloquent」 「artisan」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 caloskao/migrate-specific 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 caloskao/migrate-specific 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 caloskao/migrate-specific 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
PHP module for MySql database
VV database abstraction layer with query builder and DB structure models
统计信息
- 总下载量: 15.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-26