drfraker/snipe-migrations
Composer 安装命令:
composer require drfraker/snipe-migrations
包简介
Blazing fast database migrations for Laravel tests.
README 文档
README
Snipe Migrations
Blazing fast database migrations for Laravel tests.
The package takes a snapshot of your mysql database and imports the schema to your test database rather than running all of your migrations when the test suite starts up.
If you have a project with many migration files, this process can provide you with a massive speed improvement when initializing your test suite. This package can be used as a replacement for the RefreshDatabase trait that is provided out of the box with Laravel.
As an example, we tested this on an application that takes about 4 seconds to run all migrations with RefreshDatabase. Using SnipeMigrations the tests start up in 200 ms.
Requirements
- Laravel >= 5.5
- PHP >= 7.1
- MySql or MariaDb, with separate database for testing.
- For example if you have a development database for your application called
amazingappyou would create a test database calledamazingapp_testand add the details of the database in your phpunit.xml file.amazingapp_testis the database that Snipe will keep in sync for you.
- For example if you have a development database for your application called
Installation
Require the package using composer.
composer require --dev drfraker/snipe-migrations
Usage
After you've installed the package via composer
- Add the
SnipeMigrationstrait to yourtests/TestCasefile. Don't forget to import the class at the top of the file. Once you have added theSnipeMigrationstrait, simply use the RefreshDatabase trait in any tests in which you wish to use database access, and Snipe will handle the rest for you.
When you're done, your tests/TestCase.php file should look like this.
<?php namespace Tests; use Drfraker\SnipeMigrations\SnipeMigrations; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { use CreatesApplication, SnipeMigrations; }
-
By default, SnipeMigrations will store a
.snipefile and thesnipe_snapshot.sqlfile in/vendor/drfraker/snipe-migrations/snapshots. If you would like to change the location of the files follow the directions below to publish the snipe config file.- To publish the snipe config file, run
php artisan vendor:publishand selectsnipe-configfrom the list.
- To publish the snipe config file, run
-
If the snipe_snapshot.sql file gets out of sync for any reason you can clear it by running
php artisan snipe:clear. After running this command your original database migrations will run again creating a newsnipe_snapshot.sqlfile.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
drfraker/snipe-migrations 适用场景与选型建议
drfraker/snipe-migrations 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 401.58k 次下载、GitHub Stars 达 289, 最近一次更新时间为 2019 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 drfraker/snipe-migrations 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 drfraker/snipe-migrations 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 401.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 289
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-20