ekoukltd / s3-import-export
轻松地将Laravel模型(表)导入/导出为本地或S3存储的JSON文件。当您不需要恢复整个备份,只需几个表时使用。
1.0.4
2023-03-15 22:04 UTC
Requires
- php: ^7.4|^8.0
- illuminate/support: ^8 || ^9
- league/flysystem-aws-s3-v3: ^3.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
README
是否曾需要在服务器环境之间复制选定的模型?或者用最新内容填充数据库?
此包将模型导出到S3或其他远程磁盘,保存为JSON文件。
这不是一个健壮的备份服务
仅作为在不同环境之间移动基于内容的模型的一个工具,无需任何麻烦。
安装
通过composer安装此包
composer require ekoukltd/s3-import-export
配置
发布配置文件到config/s3-import-export.php
php artisan vendor:publish --provider="Ekoukltd\S3ImportExport\S3IOServiceProvider" --tag="config"
并定义哪些内容应导出到哪里。对于S3,您需要设置league/filesystem,请参阅:https://laravel.net.cn/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', ];
使用方法
#Export from the CLI php artisan data:export #Import php artisan data:import #Or in a scheduled task: Artisan::call('data:export');
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
贡献
请参阅 CONTRIBUTING 了解详情。
安全性
如果您发现任何安全相关的问题,请通过电子邮件 support@ekouk.com 联系,而不是使用问题跟踪器。
鸣谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。