

GitHub - drfraker/snipe-migrations: Blazing fast database migrations for Laravel...
source link: https://github.com/drfraker/snipe-migrations
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md
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.2
- PHP >= 7.1
- MySql or MariaDb, with separate database for testing.
- For example if you have a development database for your application called
amazingapp
you would create a test database calledamazingapp_test
and add the details of the database in your phpunit.xml file.amazingapp_test
is 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 following code to your
tests/TestCase
file. Don't forget to import the classes at the top of the file. -
By default, SnipeMigrations will store the
.snipe
file and thesnipe_snapshot.sql
file in the root oftests/
. 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:publish
and selectsnipe-config
from the list.
- To publish the snipe config file, run
-
To utilize SnipeMigrations, all you need to do is
use DatabaseTransactions
in your tests. WhenDatabaseTransactions
is detected SnipeMigrations will create and use a snapshot of your database to keep your test database in sync. -
(optional) Add the files
tests/.snipe
andtests/snipe_snapshot.sql
to your .gitignore.
// Add this code block to tests/TestCase, just below the use CreatesApplication; statement. public function setUpTraits() { $uses = parent::setUpTraits(); if (isset($uses[DatabaseTransactions::class])) { (new Snipe())->importSnapshot(); } }
When you're done, you're tests/TestCase.php
file should look like this.
<?php namespace Tests; use Drfraker\SnipeMigrations\Snipe; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { use CreatesApplication; // Code you added in step 1. public function setUpTraits() { $uses = parent::setUpTraits(); if (isset($uses[DatabaseTransactions::class])) { (new Snipe())->importSnapshot(); } } // End of added code. }
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
Recommend
-
129
Dealing with Data Migrations on Multi Tenant — LaravelI work on a project that sometimes require data change for all customers. Since each customer have it’s own database, we always end up working on a scrip...
-
85
README.md
-
22
README.md Flyway by Boxfuse
-
7
Test Your Laravel Migrations Skills This repository is a test for you: perform a set of tasks listed below, and fix the PHPUnit tests, which are currently intentionally failing. To test if all the functions work correctly, the...
-
5
How To Install Snipe-IT Asset Management on CentOS 8IntroductionSnipe-IT is a Free Open Source project built on Laravel made for IT asset management. This is to for example help to enable IT departments to track who has which laptop,...
-
16
<?xml encoding="utf-8" ??>Introduction Snipe-IT is a free and open-source project designed to handle IT asset management. It can handle keeping track of assets such as laptops, software, and lic...
-
6
<?xml encoding="utf-8" ??>Snipe-IT is an open-source Information Technology asset management tool that works on a Linux, Apache, MySQL, and PHP (LAMP) stack. With a powerful and user-friendly interface, S...
-
7
Lucid This package allows you to declare database migrations and factory definitions inside of your Laravel models. Running the lucid:migrate command will automatically apply any changes you've made inside your
-
4
// Tutorial //How To Use Migrations to Create and Manage Database Tables in LaravelPublished on December 17, 2020 · Updated on April 29, 2022By
-
3
Access denied Access denied Error code 1020 You do not have access to azhuge233.com.The site owner may have set restrictions that prevent you from accessing the site. Contact the site owner for ac...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK