2017 © Pedro Peláez
 

library importer

Laravel package for importing data from another database

image

dpc/importer

Laravel package for importing data from another database

  • Saturday, April 7, 2018
  • by DPC
  • Repository
  • 1 Watchers
  • 11 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Total Downloads Latest Stable Version License, (*1)

Laravel Importer

Requirements:

  • PHP 7
  • Laravel 5.6

Why?

This package allows you to import data from another database locally., (*2)

The entire seeding process is run in a transaction by default, (*3)

How?

Installation:

Use composer to install the package:, (*4)

composer require dpc/importer

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

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

Publish the vendor files by running:, (*6)

php artisan vendor:publish

This will create an importer.php config file in config directory, (*7)

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., (*8)

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., (*9)

An example of the config file:, (*10)

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., (*11)

The Seeder class should implement these 2 methods:, (*12)

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, (*13)

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

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

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

The entire seeding operation is wrapped inside a transaction., (*17)

Running The Seeds:

To run the seeds:, (*18)

php artisan importer:import

Lastly....

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

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., (*20)

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

Wanna contact me?

  • Twitter: @DPC_22
  • Email: dylan.dpc@gmail.com

The Versions

07/04 2018

dev-master

9999999-dev

Laravel package for importing data from another database

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dylan DPC

18/04 2017

v1.0.0

1.0.0.0

Laravel package for importing data from another database

  Sources   Download

MIT

The Requires

 

by Dylan DPC