kdabrow/seeder-once
Composer 安装命令:
composer require kdabrow/seeder-once
包简介
Run your laravel seeders only once
README 文档
README
Laravel Seeder Once
This library allows you to run your Laravel seeders only once.
No matter how many times artisan command db:seed is called. Done seeders will never be executed again.
Sponsored by Givore and Mistflare
How it works
Works similarly to migrations. First creates table in database, then logs all seeds that extend abstract class Kdabrow\SeederOnce\SeederOnce. In nutshell this will prevent to execute method run() if was executed in the past. Mechanism of logging data into database is heavily inspired by Laravel migration mechanism from package illuminate/database.
How to use it
1. Install it
By composer:
| php | laravel / lumen | seeder-once |
|---|---|---|
| 8.3, 8.4 | 13.0 | composer require "kdabrow/seeder-once: ^6.1" |
| 8.2, 8.3, 8.4 | 10.0, 11.0, 12.0 | composer require "kdabrow/seeder-once: ^6.1" |
| 8.2, 8.3, 8.4 | 12.0 | composer require "kdabrow/seeder-once: ^6.0" |
| 8.2, 8.3 | 10.0, 11.0 | composer require "kdabrow/seeder-once: ^5.0" |
| 8.1, 8.2 | 10.0 | composer require "kdabrow/seeder-once: ^4.0" |
| 8.0, 8.1 | 9.21 | composer require "kdabrow/seeder-once: ^3.0" |
| 7.3, 7.4, 8.0 | 8.0, 9.0 | composer require "kdabrow/seeder-once: ^2.2" |
| 7.2, 7.3, 7.4, 8.0 | 6.0, 7.0 | composer require "kdabrow/seeder-once: ^1.2" |
In Lumen do not forget to register provider in bootstrap/app.php
$app->register(Kdabrow\SeederOnce\Providers\SeederOnceProvider::class);
2. Create seeders table in database
Use this command:
php artisan db:install
This step is optional. Trait SeederOnce detects if table exists. If not, creates it automatically.
3. Extend seeders that you want to be run only once with SeederOnce
So result should look like this:
use Kdabrow\SeederOnce\SeederOnce; class SomeSeeder extends SeederOnce { /** * Seed the application's database. * * @return void */ public function run() { // } }
This prevents to seed class SomeSeeder if was already seeded before.
Tip: Always replace class Seeder with SeederOnce. Otherwise, db:seed command might print unexpected results.
Configuration
Run seeder many times
It is possible to overwrite default functionality by change parameter $seedOnce to false:
use Kdabrow\SeederOnce\SeederOnce; class DatabaseSeeder extends SeederOnce { public bool $seedOnce = false; /** * Seed the application's database. * * @return void */ public function run() { // } }
Such seeder will run like normal laravel seeder (as many times as called).
Configuration file
It is possible to publish configuration file:
php artisan vendor:publish --tag=seederonce.config
Table name
Default table name is: seeders
Console output
By default, seeder-once changes output of db:seed console command. Seeders that were run in the past will not be printed in the command output. It's possible to change that behaviour in configuration or by env variable:
SEEDER_ONCE_PRINT_OUTPUT=true
Output for already run seeders looks like this:
Database\Seeders\SomeSeeder was already seeded ..................... DONE
kdabrow/seeder-once 适用场景与选型建议
kdabrow/seeder-once 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 175.4k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2020 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「php」 「laravel」 「seeder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kdabrow/seeder-once 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kdabrow/seeder-once 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kdabrow/seeder-once 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
PHP module for MySql database
Alfabank REST API integration
统计信息
- 总下载量: 175.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-13