Coder Social home page Coder Social logo

importer's Introduction

Total Downloads Latest Stable Version License

Laravel Importer

Requirements:

  • PHP 7
  • Laravel 5.6

Why?

This package allows you to import data from another database locally.

The entire seeding process is run in a transaction by default

How?

Installation:

Use composer to install the package:

composer require dpc/importer

Install the service provider in your config file (config/app.php)

'providers' => [
    ....
    Dpc\Importer\Providers\ImporterServiceProvider::class,
];

Publish the vendor files by running:

php artisan vendor:publish

This will create an importer.php config file in config directory

Initialization:

Make sure you have created a new database connection for your temporary database (from where you want to import the data) and it contains the required data.

You need to set up the connection name along with the array of the seeders in the config file. The array will determine the order in which the seeders run.

An example of the config file:

return [
    'connection' => 'temp',

    'seeds' => [
        \App\Seeds\UserSeeder::class,
        \App\Seeds\PostSeeder::class,
    ]
];

Creating The Seeders:

Create your own Seeder class that extends Dpc\Importer\AbstractSeed.

The Seeder class should implement these 2 methods:

getData(): This function is responsible for fetching the data from the database into the seeder. This function does not return the data but an instance of the seeder. The data is available in $this->data

seed() : This function is called after data is loaded into the class property. Define your seeding process here.

prepareData() : This is an optional function that is called before the data is seeded. Can be used to

The connection is injected into the seeds so you can use $this->manager->table(<tableName>) to access the data in the temporary database.

The entire seeding operation is wrapped inside a transaction.

Running The Seeds:

To run the seeds:

php artisan importer:import

Lastly....

Do star this repo. It means a lot to the author (oh wait.. that's me :P )

What's Next?

  • Data Chunking
  • Flexibility to queue the seeders
  • Option to run using a cron job

Wanna Contribute?

Not fussy about standards so just drop in a PR.

If you find any issues or want to make future proposals, create an issue here.

Wanna contact me?

importer's People

Contributors

dylan-dpc avatar bey9s avatar

Watchers

 avatar

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.