Home > PHP Framework > Laravel > [New feature in Laravel 8] Use schema:dump to speed up migration and testing

[New feature in Laravel 8] Use schema:dump to speed up migration and testing

藏色散人
Release: 2020-08-11 14:17:01
forward
2277 people have browsed it

The following tutorial column will introduce you to the new features of Laravel 8: using schema:dump to speed up migration and testing. I hope it will be helpful to friends in need!

Laravel 8 will release a new

schema:dump[New feature in Laravel 8] Use schema:dump to speed up migration and testing command later this year. This command is useful for existing projects as it removes old migrations that are no longer needed and speeds up the testing and CI process. Taylor Otwell explains this functionality in his

pull request

: This PR adds the php artisan schema:dump

command, which uses mysqldump or pgdump dumps the current state of the schema into the database/schema/{connection}-schema.mysql file.

When this file exists and php artisan migration or

php artisan migration:fresh

has been run and no migration has been performed on database z (migration table is empty), This schema file will be loaded into the database first and then all outstanding migrations will be executed. This means that the schema file is typically only valid for use during local development or CI testing. In production, you typically already have migrations running in the past, so this schema file is never triggered. After running schema:dump

and the schema dump file exists in the project, you can delete the old migration file that you have migrated to production.

This feature solves two problems: 1. It will clear old migration files in the schema folder, which may be large in old projects.

2. Due to the schema file, the test runs much faster, and Laravel does not need to perform all migrations during the test process.

The command will look like this in your project:

php artisan schema:dump

# 自动清理旧迁移文件
php artisan schema:dump --prune

# 指定数据库链接
php artisan schema:dump --database=pgsql
Copy after login

This feature has been merged into the

master

branch, which means it will be available in Laravel 8 . To learn more about this feature, your best bet is

8.x Schema Dump

. Original address: https://laravel-news.com/schema-dump

Translation address: https://learnku.com/laravel/t/43497

The above is the detailed content of [New feature in Laravel 8] Use schema:dump to speed up migration and testing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template