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 newschema:dump 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
When this file exists and
php artisan migration:freshphp artisan migration
orhas 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.
and the schema dump file exists in the project, you can delete the old migration file that you have migrated to production.After running
schema:dump
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
This feature has been merged into the
masterbranch, 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
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!