Giter Club home page Giter Club logo

db-exporter's Introduction

Scrutinizer Code Quality 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

Add "elimuswift/db-exporter"* as a requirement to composer.json:

{
    "require": {
        "elimuswift/db-exporter": "*"
    },
}

Update composer:

php composer.phar update

For laravel <=5.4, Add the service provider to config/app.php:

 Elimuswift\DbExporter\DbExportHandlerServiceProvider::class

(Optional) Publish the configuration file.

php artisan vendor:publish --provider="Elimuswift\DbExporter\DbExportHandlerServiceProvider"

After publishing the config file make sure you change storage location for migrations and seeds.

Use dev-master as version requirement to be on the cutting edge

Documentation

From the commandline

Export database to migration

Basic usage

php artisan db-exporter:migrations

Specify a database

php artisan db-exporter:migrations otherDatabaseName

Ignoring tables

You can ignore multiple tables by seperating them with a comma.

php artisan db-exporter: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 db-exporter:seeds

Important: This requires your database config file to be updated in config/database.php**

Uploading migrations/seeds to Storage Disk

Important: The package backup destinations paths should match your desired disk location

You can backup migrations and / or seeds to a storage disk that you application supports.

php artisan db-exporter:backup --migrations

Or upload the seeds to the production server:

php artisan db-exporter:backup --seeds

Or even combine the two:

php artisan db-exporter:backup --migrations --seeds

This feature uses Laravel's filesystem.

You must configure your storage and then specify the disk name in the config file. The default disk is local

Export current database

This class will export the database name from your config/database.php file, based on your 'default' option.

DbExporter::migrate();

Export a custom database

DbExporter::migrate('otherDatabaseName');

Database to seed

This will write a seeder class with all the data of the current database.

DbExporter::seed();

Seed a custom database

Just pass the nameof the database to be seeded.

DbExporter::seed('myOtherDB');

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:

DbExporter::migrate()->seed();

Or with:

DbExporter::migrateAndSeed();

Ignoring tables

By default the migrations table is ignored. You can add tabled to ignore with the following syntax:

DbExporter::ignore('tableToIgnore')->migrateAndSeed();
DbExporter::ignore('table1','table2','table3')->migrateAndSeed();

You can also pass an array of tables to ignore.

From the configuration file

Ignore tables for seeder

If you want to always ignore certain tables you can do it on the config file

return [
    'seeds' => [
        'ignore_tables' => [
            'table_to_ignore1',
            'table_to_ignore2'
        ]
    ]
];

With this configuration every time when the command php artisan db-exporter:seeds is executed will ignore the tables on the array

Just use selected tables for seeder

In the other hand, If you want to use always certain tables you can do it on the config file

return [
    'seeds' => [
        'use_tables' => [
            'table_to_ignore1',
            'table_to_ignore2'
        ]
    ]
];

With this configuration every time when the command php artisan db-exporter:seeds is executed will only be executed to the tables on the array

Credits

Credits to @nWidart the original creator of the package DbExporter. I couldn't get it working as-is, so I decided to rewrite the package to fit the latest versions of laravel, and added a couple a features of my own.

db-exporter's People

Contributors

scrutinizer-auto-fixer avatar skalero01 avatar weezqyd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

db-exporter's Issues

Folder structure issue

When u run first time php artisan db-exporter:migrations it throws error with

failed to open stream: No such file or directory

After i created manually backup/migrations and backup/seeds, everithing went smoothly.

Problem when I'm trying install it

I'm junior in Laravel , when I'm trying to install it I face this problem .
I used composer require elimuswift/db-exporter dev-master
And composer require elimuswift/db-exporter
I googled it this issue and I don't found how to solve it
`Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for elimuswift/db-exporter dev-master -> satisfiable by elimuswift/db-exporter[dev-master].
- Conclusion: remove laravel/framework v7.6.1
- Conclusion: don't install laravel/framework v7.6.1
- elimuswift/db-exporter dev-master requires illuminate/filesystem ^5.2 -> satisfiable by illuminate/filesystem[5.2.x-dev, 5.3.x-dev, 5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.17, 5.7.18, 5.7.19, 5.7.x-dev, 5.8.x-dev, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34, v5.5.35, v5.5.36, v5.5.37, v5.5.39, v5.5.40, v5.5.41, v5.5.43, v5.5.44, v5.6.0, v5.6.1, v5.6.10, v5.6.11, v5.6.12, v5.6.13, v5.6.14, v5.6.15, v5.6.16, v5.6.17, v5.6.19, v5.6.2, v5.6.20, v5.6.21, v5.6.22, v5.6.23, v5.6.24, v5.6.25, v5.6.26, v5.6.27, v5.6.28, v5.6.29, v5.6.3, v5.6.30, v5.6.31, v5.6.32, v5.6.33, v5.6.34, v5.6.35, v5.6.36, v5.6.37, v5.6.38, v5.6.39, v5.6.4, v5.6.5, v5.6.6, v5.6.7, v5.6.8, v5.6.9, v5.7.0, v5.7.1, v5.7.10, v5.7.11, v5.7.15, v5.7.2, v5.7.20, v5.7.21, v5.7.22, v5.7.23, v5.7.26, v5.7.27, v5.7.28, v5.7.3, v5.7.4, v5.7.5, v5.7.6, v5.7.7, v5.7.8, v5.7.9, v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9].
- don't install illuminate/filesystem 5.2.x-dev|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem 5.3.x-dev|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem 5.4.x-dev|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem 5.5.x-dev|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem 5.6.x-dev|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem 5.7.17|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem 5.7.18|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem 5.7.19|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem 5.7.x-dev|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem 5.8.x-dev|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.0|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.19|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.21|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.24|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.25|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.26|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.27|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.28|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.31|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.32|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.37|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.43|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.45|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.6|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.2.7|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.3.0|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.3.16|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.3.23|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.3.4|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.4.0|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.4.13|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.4.17|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.4.19|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.4.27|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.4.36|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.4.9|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.0|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.16|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.17|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.2|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.28|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.33|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.34|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.35|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.36|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.37|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.39|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.40|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.41|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.43|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.5.44|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.0|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.1|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.10|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.11|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.12|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.13|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.14|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.15|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.16|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.17|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.19|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.2|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.20|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.21|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.22|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.23|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.24|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.25|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.26|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.27|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.28|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.29|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.3|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.30|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.31|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.32|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.33|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.34|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.35|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.36|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.37|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.38|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.39|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.4|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.5|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.6|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.7|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.8|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.6.9|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.0|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.1|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.10|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.11|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.15|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.2|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.20|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.21|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.22|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.23|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.26|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.27|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.28|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.3|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.4|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.5|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.6|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.7|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.8|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.7.9|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.0|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.11|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.12|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.14|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.15|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.17|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.18|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.19|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.2|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.20|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.22|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.24|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.27|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.28|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.29|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.3|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.30|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.31|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.32|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.33|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.34|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.35|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.36|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.4|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.8|don't install laravel/framework v7.6.1
- don't install illuminate/filesystem v5.8.9|don't install laravel/framework v7.6.1
- Installation request for laravel/framework (locked at v7.6.1) -> satisfiable by laravel/framework[v7.6.1].

Installation failed, reverting ./composer.json to its original content.
`

This composer.json file :
{ "name": "laravel/laravel", "type": "project", "description": "The Laravel Framework.", "keywords": [ "framework", "laravel" ], "license": "MIT", "require": { "php": "^7.2.5", "fideloper/proxy": "^4.2", "fruitcake/laravel-cors": "^1.0", "guzzlehttp/guzzle": "^6.3", "illuminate/support": "^7.6", "laravel/tinker": "^2.0", "laravel/ui": "^2.0" }, "require-dev": { "facade/ignition": "^2.0", "fzaninotto/faker": "^1.9.1", "mockery/mockery": "^1.3.1", "nunomaduro/collision": "^4.1", "phpunit/phpunit": "^8.5" }, "config": { "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true }, "extra": { "laravel": { "dont-discover": [] } }, "autoload": { "psr-4": { "App\\": "app/" }, "classmap": [ "database/seeds", "database/factories" ] }, "autoload-dev": { "psr-4": { "Tests\\": "tests/" } }, "minimum-stability": "dev", "prefer-stable": true, "scripts": { "post-autoload-dump": [ "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", "@php artisan package:discover --ansi" ], "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "@php artisan key:generate --ansi" ] } }

Thanks ..

Time fields not recognised?

Thanks for the package - does exactly what I needed!

I've just created a migration from existing data - however it didn't appear to pick up time type fields. I had this in the migration file:

    $table->('am_tee')->nullable();
    $table->('end_time')->nullable();

I've edited the file manually in the meantime

Error in adding ServiceProvider Elimuswift\DbExporter\DbExportServiceProvider::class

I found the correct file to be DbExportHandlerServiceProvider. So the service provider that should be in the config/app.php is "Elimuswift\DbExporter\DbExportHandlerServiceProvider::class"

And the corresponding config publish command is
php artisan vendor:publish --provider="Elimuswift\DbExporter\ DbExportHandlerServiceProvider"

Thanks

Undefined variable: stub

I keep getting this error when running php artisan db-exporter:seeds

 Undefined variable: stub

full exception trace

Preparing the seeder class for database starter_db

   ErrorException  : Undefined variable: stub

  at /Users/*/Sites/Code/Laravel/*/vendor/elimuswift/db-exporter/src/DbExporter/DbSeeding.php:136
    132|             $this->saveData("'.$tableName.'", $item);
    133|         }';
    134|             }
    135| 
  > 136|             $result[$tableName] = $stub; 
    137|         }//end foreach
    138| 
    139|         $this->seedingStub = $result;
    140| 

  Exception trace:

  1   Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Undefined variable: stub", "/Users/*/Sites/Code/Laravel/*/vendor/elimuswift/db-exporter/src/DbExporter/DbSeeding.php")
      /Users/*/Sites/Code/Laravel/*/vendor/elimuswift/db-exporter/src/DbExporter/DbSeeding.php:136

  2   Elimuswift\DbExporter\DbSeeding::convert()
      /Users/*/Sites/Code/Laravel/*/vendor/elimuswift/db-exporter/src/DbExporter/DbExportHandler.php:54

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.