• Stars
    star
    372
  • Rank 110,814 (Top 3 %)
  • Language
    PHP
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Export your database as a Laravel Migration. And export your DB data as a seed file. Finally sync all this with your remote server.

Scrutinizer Quality Score Latest Stable Version Total Downloads Latest Unstable Version License

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/13
  • Deploy the migration directly to the production server ready to be migrated. (as an option) 5/1/13
  • Make commands to do the same thing (export db to migration) 4/1/13
  • Make 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 , [email protected]

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.

More Repositories

1

laravel-modules

Module Management In Laravel
PHP
5,236
star
2

laravel-menus

Laravel Menu Management
PHP
150
star
3

Laravel-broadway

CQRS/Event Sourcing for laravel. Laravel adapter for Broadway.
PHP
123
star
4

Laravel-Broadway-Demo

This is a test application using https://github.com/qandidate-labs/broadway
CSS
36
star
5

nwidart-docs

HTML
32
star
6

laravel-videoable

Attach Videos to your Eloquent Models
PHP
17
star
7

HttpStatus-l4-package

Laravel 4 Packages. Adds 403,404,500 and 503 customizable error pages.
PHP
14
star
8

laravel-actuator

Add health endpoints to your applications
PHP
13
star
9

laravel-normalizer

Laravel package to normalize your data before saving into the database.
PHP
12
star
10

portfolio

Source code of my personal portfolio.
CSS
10
star
11

projectLister

Laravel package to list repositories on Github, Bitbucket and Sourceforge.
PHP
9
star
12

MoneyFormatter

A package used for money formatting
PHP
9
star
13

phpstorm-vue-snippets

PHPStorm VueJS Live templates. Based of https://github.com/sdras/vue-vscode-snippets
9
star
14

vue-symfony4

Vue
6
star
15

tech-videos

Organise learning sessions in your company to watch tech videos.
Java
4
star
16

Themify-l5

PHP
4
star
17

composer-generator

Laravel 4 Composer.json generator service.
PHP
3
star
18

cubesNcircles

cubesNcircles
JavaScript
3
star
19

laravel-modules-custom-service-provider

PHP
2
star
20

Laravel-forecast

Laravel-forecast provides a service provider and a facade arround the Forecast-php wrapper.
PHP
2
star
21

forecast-php

PHP API Wrapper for Forecast.io
PHP
2
star
22

rematch-typescript

Using rematch in typescript projects (https://github.com/rematch/rematch)
TypeScript
2
star
23

activity

Activity lets you list your current activity on Github. Soon from Bitbucket as well.
PHP
2
star
24

MoneyFormatter-Laravel

Laravel integration for my MoneyFormatter Package
PHP
2
star
25

Alys-Google-Maps-Organiser

Laravel App, to manage clients and their corresponding markers for Google Maps.
PHP
2
star
26

pda

Personal Diablo Assistant
PHP
1
star
27

spring-modular-tests

Java
1
star
28

modules-routes-tests

https://github.com/nWidart/laravel-modules/issues/755
PHP
1
star
29

BugTrack

Simple bug tracking app
PHP
1
star
30

nw-cleanV2

PHP
1
star
31

trivago-cqrs-es-workshop-2017

Workshop from https://github.com/ShittySoft/trivago-cqrs-es-workshop-2017
PHP
1
star
32

Grimdawntrade

PHP
1
star
33

twitter-es

Twitter clone, in event sourcing with Prooph
PHP
1
star
34

spring-boot-bean-overrides

Trying to reproduce a bean overriding issue
Java
1
star
35

heaj_trashsquare

PHP
1
star
36

export-wrapper

A PHP wrapper around Sonata-Exporter, for ease of use
PHP
1
star
37

axon-webinar

cqrs/event sourcing in java with Axon framework
Java
1
star
38

PhilipBrownBasket

This is a test ecommerce application using philipbrown/basket package.
PHP
1
star
39

spring-boot-starter-jwt

Java
1
star
40

spring-data-multi-datasource

Java
1
star
41

Product-Custom-Post-Type---Taxonomy

A Wordpress Custom Post Type and Taxonomy.
PHP
1
star
42

Alys-Zonetrial-Wordpress-theme

PHP
1
star
43

ci_trashsquare

Trashsquare made on CodeIgniter
PHP
1
star
44

FAQcms

Multilang FAQ management system.
JavaScript
1
star