ekoukltd/s3-import-export

Easy import & export of Laravel models (tables) to local or S3 Storage as a JSON file. For when you don't want to restore a whole backup, just a few tables.

1.0.4 2023-03-15 22:04 UTC

This package is auto-updated.

Last update: 2024-05-16 00:51:19 UTC


README

Latest Version on Packagist Total Downloads

Ever needed to copy selected models between server environments? Or seed a database with latest content?

This package exports models to S3 or other remote disks as a JSON file.

This is not designed to be a robust backup service

Just a tool to move content based models between different environments without any hassle.

Installation

Install the package via composer:

composer require ekoukltd/s3-import-export

Configuration

Publish the config file to config/s3-import-export.php

php artisan vendor:publish --provider="Ekoukltd\S3ImportExport\S3IOServiceProvider" --tag="config"

and define which what should be exported to where. For S3 you need to have setup league/filesystem see: https://laravel.com/docs/9.x/filesystem#s3-driver-configuration

    //Data will be exported to this disk -> choose from config.filesystems.disks options
	//Note that if using s3 a local copy will also be created in storage when importing
	//When running tests local storage copy will be used.
	'disk'           => 's3',
	
	//Where to stick em.  Note trailing slash
	'export_dir' => 'content-export/',
	
	//Add your models to import and export here
	'content_models' => [
		//Json object exports are ideal for copying content type data like pages, posts and templates 
		//without affecting the reset of the database
		'App\\Models\\Pages',
		'App\\Models\\Posts',
		'App\\Models\\EmailTemplates',
	],
	 
	 /** IMPORTANT **/
	//Carbon dates export with a timezone by default, which throws an error when importing to sql
	//If your using timestamps either set any other date fields here 
	'date_columns' => ['created_at', 'updated_at', 'deleted_at']
    
    //or set the format in the model
    protected $casts = [
        'email_verified_at' => 'datetime:Y-m-d H:i:s'
        'my_date_field'     => 'datetime:Y-m-d H:i:s',
    ];

Usage

#Export from the CLI
php artisan data:export

#Import
php artisan data:import

#Or in a scheduled task:
Artisan::call('data:export');

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email support@ekouk.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.