maxim-oleinik/blade-migrations-laravel
Composer 安装命令:
composer require maxim-oleinik/blade-migrations-laravel
包简介
An intelligent alternative version of Laravel Database Migrations - uses raw-sql syntax, transactions, auto-rollback, UP-DOWN-UP testing
README 文档
README
rus /
An intelligent alternative version of Laravel 5 Database Migrations
Features
- Using raw SQL queries
- you can use all the capabilities of your database to describe the structure and changes
- easy work with procedures and functions
- safe data migrations (INSERT/UPDATE)
- IDE native syntax support
- Running migrations within a transaction with automatic rollback in case of an error (if your database supports it, PostgreSQL for example)
- Dynamic output running the SQL-queries
- Automatic rollback after switching the branch (for reviewing, testing, demo, building at permanent/staging database)
- Auto-update the migration after editing (version change in the name of the migration file)
- Apply with rollback testing -
UD-DOWN-UP - Rollback or Reload any selected migration
Requirements
- PHP >= 7.0
- Laravel >= 5.1 (supports all versions 5.1 - 8.X)
Syntax
--TRANSACTION- if specified, the migration will be launched within a transaction- Instructions are separated by
--UPand--DOWNtags. - The SQL queries are separated by
";"(the last character at the end of the line)
--TRANSACTION
--UP
ALTER TABLE authors ADD COLUMN code INT;
ALTER TABLE posts ADD COLUMN slug TEXT;
--DOWN
ALTER TABLE authors DROP COLUMN code;
ALTER TABLE posts DROP COLUMN slug;
If you need to change the delimiter (when in SQL you have to use ";")
--SEPARATOR=@
--UP
... some sql ...@
... some sql ...@
--DOWN
... some sql ...@
... some sql ...@
Install
-
Require this package with composer using the following command:
composer require maxim-oleinik/blade-migrations-laravel -
Update
config/database.php'migrations' => [ // migrations table name 'table' => 'migrations', // path to migrations dir 'dir' => __DIR__ . '/../database/migrations', ], -
Register ServiceProvider at
config/app.php
for Laravel < 5.5'providers' => [ ... Blade\Migrations\Laravel\MigrationsServiceProvider::class, ],for Laravel 6/7/8.X
replace Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class with Illuminate\Foundation\Providers\ComposerServiceProvider::class, Illuminate\Foundation\Providers\ArtisanServiceProvider::class do disable original mirgations -
Create migration table
php artisan migrate:install
Usage
Create Migration file
php artisan make:migration NAME
Status
php artisan migrate:status
+---+----+---------------------+------------------------+
| | ID | Date | Name |
+---+----+---------------------+------------------------+
| Y | 6 | 28.08.2018 20:17:01 | 20180828_195348_M1.sql |
| D | 7 | 28.08.2018 20:17:21 | 20180828_201639_M3.sql |
| A | | | 20180828_200950_M2.sql |
+---+----+---------------------+------------------------+
- Y - applied migration
- D - have to rollback (no this migration in the current branch/revision)
- A - not applied yet, next to be run
Migrate
# Apply next А-migration
php artisan migrate
# Apply the migration without a prompt
php artisan migrate -f
# Apply with rollback testing: UP-DOWN-UP
php artisan migrate -t
# Auto-migrate all - rollback all D-migrations and appply all А-migrations
php artisan migrate --auto
# Apply migration from the specified file
php artisan migrate FILE_NAME
Rollback
The migrate file with SQL-commands is saved to DB after applying the migration. So the rollback is processing from this saved instructions. This is done to be able to rollback the migration when project switches to another branch which does not contains this file.
# Rollback the latest Y-migration
php artisan migrate:rollback
# To force the rollback without a prompt
php artisan migrate:rollback -f
# Rollback migration by its ID
php artisan migrate:rollback --id=N
# Rollback migration with commands taken from migration file, not from DB (if saved version contains error)
php artisan migrate:rollback --load-file
Reload
Rollback migration and run it again
php artisan migrate:reload
# the same options as rollback
php artisan migrate:reload -f --id=N --load-file
maxim-oleinik/blade-migrations-laravel 适用场景与选型建议
maxim-oleinik/blade-migrations-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.31k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2018 年 10 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「migration」 「laravel」 「artisan」 「laravel5」 「laravel6」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maxim-oleinik/blade-migrations-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maxim-oleinik/blade-migrations-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maxim-oleinik/blade-migrations-laravel 相关的其它包
同方向 / 同关键字的高下载量 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.
Lets you add foreign keys in a swift! Foreign key adder in laravel migration.
A PSR-7 compatible library for making CRUD API endpoints
Manage PostgreSQL schemas in Laravel applications
统计信息
- 总下载量: 2.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 24
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-07