在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):orangehill/iseed开源软件地址(OpenSource Url):https://github.com/orangehill/iseed开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Inverse seed generator (iSeed) is a Laravel package that provides a method to generate a new seed file based on data from the existing database table. InstallationComposer1. Require withcomposer require orangehill/iseed Laravel 5.3.7 and below or Laravel 4 need specific version composer require orangehill/iseed:2.2 # Laravel 5.3.7 and below
composer require orangehill/iseed:1.1 # Laravel 4 2. Add Service Provider (Laravel 5.4 and below)Latest Laravel versions have auto dicovery and automatically add service provider - if you're using 5.4.x and below, remember to add it to // ...
Orangehill\Iseed\IseedServiceProvider::class, Artisan command options[table_name]Mandatory parameter which defines which table/s will be used for seed creation. Use CSV notation for multiple tables. Seed file will be generated for each table. Examples:
classnameprefix & classnamesuffixOptionally specify a prefix or suffix for the Seeder class name and file name. This is useful if you want to create an additional seed for a table that has an existing seed without overwriting the existing one. Examples:
outputs CustomizedMyTableSeeder.php
outputs CustomizedMyTableSeeder.php and CustomizedAnotherTableSeeder.php
outputs MyTableCustomizationsSeeder.php
outputs MyTableCustomizationsSeeder.php and AnotherTableCustomizationsSeeder.php forceOptional parameter which is used to automatically overwrite any existing seeds for desired tables Example:
The following command will overwrite
dumpautoOptional boolean parameter that controls the execution of Example that will stop
cleanOptional parameter which will clean Example:
databaseOptional parameter which specifies the DB connection name. Example:
maxOptional parameter which defines the maximum number of entries seeded from a specified table. In case of multiple tables, limit will be applied to all of them. Example:
chunksizeOptional parameter which defines the size of data chunks for each insert query. Example:
orderbyOptional parameter which defines the column which will be used to order the results by, when used in conjunction with the max parameter that allows you to set the desired number of exported database entries. Example:
directionOptional parameter which allows you to set the direction of the ordering of results; used in conjuction with orderby parameter. Example:
excludeOptional parameter which accepts comma separated list of columns that you'd like to exclude from tables that are being exported. In case of multiple tables, exclusion will be applied to all of them. Example:
prerunOptional parameter which assigns a laravel event name to be fired before seeding takes place. If an event listener returns Example: The following command will make a seed file which will fire an event named 'someEvent' before seeding takes place.
The following example will assign
The following example will only assign a
postrunOptional parameter which assigns a laravel event name to be fired after seeding takes place. If an event listener returns Example: The following command will make a seed file which will fire an event named 'someEvent' after seeding was completed.
The following example will assign
The following example will only assign a
noindexBy using --noindex the seed can be generated as a non-indexed array. The use case for this feature is when you need to merge two seed files. Example:
UsageTo generate a seed file for your users table simply call: This will create a file inside a <?php
// File: /database/seeds/UsersTableSeeder.php
class UsersTableSeeder extends Seeder {
/**
* Auto generated seed file
*
* @return void
*/
public function run()
{
\DB::table('users')->truncate();
\DB::table('users')->insert(array (
0 =>
array (
'id' => '1',
'email' => '[email protected]',
'password' => '$2y$10$tUGCkQf/0NY3w1l9sobGsudt6UngnoVXx/lUoh9ElcSOD0ERRkK9C',
'permissions' => NULL,
'activated' => '1',
'activation_code' => NULL,
'activated_at' => NULL,
'last_login' => NULL,
'persist_code' => NULL,
'reset_password_code' => NULL,
'first_name' => NULL,
'last_name' => NULL,
'created_at' => '2013-06-11 07:47:40',
'updated_at' => '2013-06-11 07:47:40',
),
1 =>
array (
'id' => '2',
'email' => '[email protected]',
'password' => '$2y$10$ImNvsMzK/BOgNSYgpjs/3OjMKMHeA9BH/hjl43EiuBuLkZGPMuZ2W',
'permissions' => NULL,
'activated' => '1',
'activation_code' => NULL,
'activated_at' => NULL,
'last_login' => '2013-06-11 07:54:57',
'persist_code' => '$2y$10$C0la8WuyqC6AU2TpUwj0I.E3Mrva8A3tuVFWxXN5u7jswRKzsYYHK',
'reset_password_code' => NULL,
'first_name' => NULL,
'last_name' => NULL,
'created_at' => '2013-06-11 07:47:40',
'updated_at' => '2013-06-11 07:54:57',
),
));
}
} This command will also update If you wish you can define custom iSeed template in which all the calls will be placed. You can do this by using <?php
// File: /database/seeds/DatabaseSeeder.php
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
if(App::environment() == "local")
{
throw new \Exception('Only run this from production');
}
#iseed_start
// here all the calls for newly generated seeds will be stored.
#iseed_end
}
} Alternatively you can run Iseed from the command line using Artisan, e.g. In case you try to generate seed file that already exists command will ask you a question whether you want to overwrite it or not. If you wish to overwrite it by default use If you wish to clear iSeed template you can use Artisan Command Option You can specify db connection that will be used for creation of new seed files by using Artisan Command Option To limit number of rows that will be exported from table use Artisan Command Option To (re)seed the database go to the Terminal and run Laravel's Please note that some users encountered a problem with large DB table exports (error when seeding from table with many records). The issue was solved by splitting input data into smaller chunks of elements per insert statement. As you may need to change the chunk size value in some extreme cases where DB table has a large number of columns, the chunk size is configurable in iSeed's
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论