nwidart/db-exporter
Composer 安装命令:
composer require nwidart/db-exporter
包简介
Export your database quickly and easily as a Laravel Migration and all the data as a Seeder class.
README 文档
README
Database Exporter
Export your database quickly and easily as a Laravel Migration and all the data as a Seeder class. This can be done via artisan commands or a controller action.
Please note that I've only tested this package on a MySQL database. It has been confirmed it does not work with Postgres.
Installation
$ composer require nwidart/db-exporter
Add the service provider to app/config/app.php:
'Nwidart\DbExporter\DbExportHandlerServiceProvider'
(Optional) Publish the configuration file.
php artisan config:publish nwidart/db-exporter
Use dev-master as version requirement to be on the cutting edge
Documentation
From the commandline
Export database to migration
Basic usage
php artisan dbe:migrations
Specify a database
php artisan dbe:migrations otherDatabaseName
Ignoring tables
You can ignore multiple tables by seperating them with a comma.
php artisan dbe:migrations --ignore="table1,table2"
Export database table data to seed class
This command will export all your database table data into a seed class.
php artisan dbe:seeds
Important: This requires your database config file to be updated in app/config/database.php.
Uploading migrations/seeds to remote server
Important: This requires your app/config/remote.php to be configured.
Important: The package configuration remote key needs to be configured to correspond to your remotes directory structure.
You can with the following command, upload migrations and / or seeds to a remote host with php artisan dbe:remote remoteName [--migrations] [--seeds]
For instance to upload the migrations to the production server:
php artisan dbe:remote production --migrations
Or upload the seeds to the production server:
php artisan dbe:remote production --seeds
Or even combine the two:
php artisan dbe:remote production --migrations --seeds
From a controller / route
Database to migration
Export current database
This requires your database config file to be updated. The class will export the database name from your app/config/database.php file, based on your 'default' option.
Make a export route on your development environment
Route::get('export', function() { DbExportHandler::migrate(); });
Export a custom database
Route::get('export', function() { DbExportHandler::migrate('otherDatabaseName'); });
Database to seed
This will write a seeder class with all the data of the current database.
Route::get('exportSeed', function() { DbExportHandler::seed(); });
Next all you have to do is add the call method on the base seed class:
$this->call('nameOfYourSeedClass');
Now you can run from the commmand line:
php artisan db:seed,- or, without having to add the call method:
php artisan db:seed --class=nameOfYourSeedClass
Chaining
You can also combine the generation of the migrations & the seed:
DbExportHandler::migrate()->seed();
Or with:
DbExportHandler::migrateAndSeed();
Important : Please note you cannot set a external seed database. If you know of a way to connect to a external DB with laravel without writing in the app/database.php file let me know.
Ignoring tables
By default the migrations table is ignored. You can add tabled to ignore with the following syntax:
DbExportHandler::ignore('tableToIgnore')->migrate(); DbExportHandler::ignore('tableToIgnore')->seed();
You can also pass an array of tables to ignore.
TODO
Export data too. It would be cool if it could also generate a seed file based of the data in the tables. This would be more usefull to run on the production server to get the seed on the development server.3/1/13Deploy the migration directly to the production server ready to be migrated. (as an option)5/1/13Make commands to do the same thing (export db to migration)4/1/13Make commands to do the same thing (export db to seed)4/1/13- Making the upload to remote available directly when generating the migrations/seeds
Credits
Credits to @michaeljcalkins for the original class on paste.laravel.com (which goal was to generate migrations from a database). Sadly I couldn't get it working as-is, so I debugged it and decided to make a package out of it, and added a couple a features of my own.
License (MIT)
Copyright (c) 2013 Nicolas Widart , n.widart@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
nwidart/db-exporter 适用场景与选型建议
nwidart/db-exporter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39.12k 次下载、GitHub Stars 达 378, 最近一次更新时间为 2014 年 01 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「migrations」 「php」 「command」 「export」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nwidart/db-exporter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nwidart/db-exporter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nwidart/db-exporter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
Symfony ClickhouseMigrationsBundle
Very simple SQL-based database migrations tool - a heavily stripped down fork of robmorgan/phinx
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Laravel table comments loader (part of Diplodocker project)
统计信息
- 总下载量: 39.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 383
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-01-02