spresnac/laravel-artisan-database-helper
Composer 安装命令:
composer require spresnac/laravel-artisan-database-helper
包简介
Some useful helper to handle database backup & restores
README 文档
README
This package will provide you some helper for
- Backup your database
- Restore this backups
- Drop all tables from a schema
Installation
First things first, so require the package:
composer require spresnac/laravel-artisan-database-helper
That's all, you are ready to go now 😁
Usage
BackupDatabase
The 90% way
To backup your database, open up your console and type
php artisan db:backup
and in most cases, you are done. You will find your backup in
storage/app/backups
Ok, with "most cases", i meant this:
- your are using only one database
- you want to backup everthing
- you have set the path, so a call to
mysqldumpwill work
If you have all of this, you are ready and good to go.
The other 10% ;)
Let's say, you are not one of the 90%, perhaps because
- you use more than database connection
- you want to export only the structure
- you have a
mysqldumpbut it is not in your path
I got you covered (like i had this problems too), so you can configure the way the backup is created with this options:
Define the connection to be backuped
With the first parameter, you can define the connection that is beeing used. You can set the connection within your config/database.php
php artisan db:backup <connection_name>
Define the path to your mysqldump binary
Real world example needed for this option? Ok, short-format: I am using windows ... no more words needed ;)
The second parameter can be used to define a path that points to your mysqldump binary
php artisan db:backup <connection_name> <path_to_binary>
Hint: When you only need the path to be set, but use your default connection, use mysql as connection name:
php artisan db:backup mysql <path_to_binary>
Export only the structure
Use the -S option to export only the structure of your database:
php artisan db:backup -S
Export without options
This is one option that i personally need a lot. For details why, look in the 'How i use it for testing my apps' section.
php artisan db:backup -O
Export with a date prefix
You can export with the actual date and time as a prefix to the export file name. It will look like 20190425153412_yourConnection.sql. The date format is YmdHis.
php artisan db:backup -D
Glueing it all together
All glued together (export a specific database, with a custom path, structure only with no options in it):
php artisan db:backup foobardb d:/www/mysql/bin -SO
Where is my backup?
You will find your backup in
storage/app/backups/<connection>_backup.sql
If you set the -S option, it looks like this
storage/app/backups/<connection>_structure.sql
When used with -D it will look like
storage/app/backups/<Ymd_><connection>_backup.sql
DropTable
With this command you can quickly "emtpy" a given database schema without deleting the schema itself. For short, all tables in the given connection will be deleted.
php artisan db:drop-tables <connection>
If you want to use this in an automatic way, you can use the --force option to delete the tables without confirmation (you be warned!).
php artisan db:drop-tables <connection> --force
RestoreDatabase
To restore a backup, simply use
php artisan db:restore
You can provide more options in case you need one of this:
php artisan db:restore <backup_name> <connection> <path_to_mysql> <port>
All this options are similar to the ones described in db:backup, so you are able to seamlessly restore a backuped database.
How i use it for testing or bugfixing my apps
When having complex setups for very complex bugs it may happen that you are in need of some very specific database entries you do not want to reproduce all the time.
In this case, i do use this package as a helper for me to bugfix faster.
- Create a backup from the database with
db:backup. - Rename this backup like the bugticket i have.
- Setup my unit-test for this bug in a special group, that is not executed by default.
- In my testscript, i do define a testschema.
- Before running my tests, execute
db:drop-tableson the testschema. - Right after that, execute
db:restore <ticketnumber>.
With this, everytime i execute my tests for bugfing my database is reset to this very specific point where i can reproduce the bug and fix it fast.
Finally
... have fun 😉 and be productive with it.
spresnac/laravel-artisan-database-helper 适用场景与选型建议
spresnac/laravel-artisan-database-helper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.7k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「php」 「laravel」 「artisan」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spresnac/laravel-artisan-database-helper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spresnac/laravel-artisan-database-helper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spresnac/laravel-artisan-database-helper 相关的其它包
同方向 / 同关键字的高下载量 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.
A PSR-7 compatible library for making CRUD API endpoints
PHP module for MySql database
Alfabank REST API integration
统计信息
- 总下载量: 2.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-12