orangehill / iseed Goto Github PK
View Code? Open in Web Editor NEWLaravel Inverse Seed Generator
License: BSD 2-Clause "Simplified" License
Laravel Inverse Seed Generator
License: BSD 2-Clause "Simplified" License
Thanks for your hard work,
It seems you deleted the dev-master branch, my cuestion is, will you enabled dev-master branch again? ? will be some changes??
thanks again!!
This is not an issue, rather a question.
I use another laravel provider which seeds 2 rows in 2 tables. I need all rows in 3 tables for the application to work. Do you have a way where I could generate a seed from results of a eloquent query? Model::where('id','>','2')
It would be nice if by default the seeders were stored with ::class notation instead of plain strings in DatabaseSeeder.php. It would improve consistency with L 5.1 & L 5.2. Also makes it easier to jump between files and classes in some IDEs such as PHPStorm.
public function updateDatabaseSeederRunMethod($className)
{
$className = "{$className}::class";
$databaseSeederPath = base_path() . config('iseed::config.path') . '/DatabaseSeeder.php';
$content = $this->files->get($databaseSeederPath);
if(strpos($content, "\$this->call({$className})")===false)
{
if(strpos($content, '#iseed_start') && strpos($content, '#iseed_end') && strpos($content, '#iseed_start') < strpos($content, '#iseed_end'))
{
$content = preg_replace("/(\#iseed_start.+?)\#iseed_end/us", "$1\$this->call({$className});\n\t\t#iseed_end", $content);
}
else
{
$content = preg_replace("/(run\(\).+?)}/us", "$1\t\$this->call({$className});\n\t}", $content);
}
}
return $this->files->put($databaseSeederPath, $content) !== false;
}
When I generate seeds with autoincrement columns the database lost the reference of those fields when I have to run/restore the seed, causing a duplicated key error in the moment that I add a new register of this table. This is commonly happens with id primary keys that I have to delete it from generated seed. Because of that I need to know if there is any way to generate the seed ignoring the autoincrement id columns.
My database is Postgres.
Congrats for the project!
In order to avoid Laravel from thinking that the Class just created is in a subfolder.
This happen for all relational tables.
Here's my code:
Line 107 Iseed.php
public function generateClassName($table) {
$tableString = '';
$tableName = explode('_', $table);
foreach($tableName as $tableNameExploded) {
$tableString .= ucfirst($tableNameExploded);
}
return ucfirst($tableString) . 'TableSeeder';
}
Already tested and perfectly working, also with non-relational tables
The files saved do not include non English text, I tested it with swedish
I get this error when I run php artisan comand after regisering this package.
Call to undefined method Illuminate\Foundation\Application::share()
I'm guessing the share() function has been renamed??
Hi, there is a problem, it requires to launch composer dump-autoload when new seed class is created. Maybe it's good to add dump-autoload command execution when launching php artisan iseed?
Also it adds $this->call() to DatabaseSeeder after Model::reguard(); call, it should be before. And in new Laravel 5.1 version they replaced tabs indents with spaces http://screencast.com/t/pAAUENCFzg6F
I'm not sure how this would play out with foreign keys, maybe it'd just need to ignore them? I have several tables I'd like to generate seeds for that exceed 1,000 rows and I only need about 50 for development purposes. It'd be awesome to be able to specify a max # of rows to be seeded from a given table.
As suggested in #58 (comment)
Add a key in the config like a method or any name you want.
return array( 'path' => '/database/seeds', 'chunk_size' => 500, 'method' => 'delete' );
and in the stub file send a method var
DB::table('{{table}}')->{{method}}();
For the people with foreign keys problems, it can be solve with this:
Schema::disableForeignKeyConstraints();
$this->call(SomeTableSeeder::class);
Schema::enableForeignKeyConstraints();
Just installed this on 5.1 but it does not work. Whatever I try I keep getting the below error! Althought php artisan vendor:publish
does not seem to publish the package config file i have created it manually with no luck. Also when running the command i added the max option and still no luck.
php artisan iseed users -max=100
[ErrorException]
array_chunk(): Size parameter expected to be greater than 0
I was able to create seed classes using iseed command. But when I try to re-seed the data by running php artisan db:seed command, this error shows up:
[ReflectionException] Class TableNameTableSeeder does not exist
I'm using Laravel 5.1.
Thanks.
It looks like Lumen doesn't pull in some packages that iseed rely on โ e.g. \Illuminate\Foundation
Please change the hasTable check in generateFileName
https://github.com/orangehill/iseed/blob/master/src/Orangehill/Iseed/IseedCommand.php#L158
to
if (!\Schema::connection($database)->hasTable($table)) {
and add
$database = $this->option('database') ?: config('database.default');
to
https://github.com/orangehill/iseed/blob/master/src/Orangehill/Iseed/IseedCommand.php#L51
and change
https://github.com/orangehill/iseed/blob/master/src/Orangehill/Iseed/IseedCommand.php#L70
to:
list($fileName, $className) = $this->generateFileName($database, $table);
Thanks.
Hey there,
If you add --max=X
parameter, is there a way to add data in descending order, so the last X records are added.
Something like:
php artisan iseed contacts --max=10 --sort=desc
Thanks in advance!
After installing the package, When I am trying php artisan iseed my_table
in command line, I am getting error that command iseed is not defined.
Hi guys,
search but not found generated seed whithout update DatabaseSeeder file.
I would like to update the seed file from a table but do not change the databaseSeeder file, is this possible?
Sorry my English. ๐
Hi everybody,
Why using
public function run()
{
\DB::table('{{table}}')->truncate();
It happens issues with foreigns keys.
I think you should update this with delete.
Regards,
After updating to the latest of iseed (dev-master
) I receive the following error when using composer require
or composer update
I am using L5.1. I believe that L5.1 uses Illuminate\Foundation\Composer instead of Illuminate\Foundation\Composer. I was able to put a bandaid on this by specifying a previous commit in composer.json and running composer update --no-scripts
to get me by for now. If you need anything else let me know.
Thanks for all the work you do on this package. It's greatly appreciated!
I didn't find it...
But if there isn't it would be good to have a --allTables
parameter to seed all the tables in a DB and a
--excludeTable
to eventually exclude some of them.
Expected behaviour:
When every record is gets created, I expect my model created event to fire off to do some other things.
Actual Behaviour:
My model event created method is only called once, instead of once for each record created. This only happened to seeder files generated by iSeed. Possibly due to iSeed auto generated seeder files using bulk inserts (If I don't remember wrongly)
Hi,
I am very happy about iseed, it saves me tons of work. But I use it on Linux and therefore tend to get weird Windos CRLF characters in my source code (which I occasionally edit manually).
Is there any chance that you can change this line:
private $newLineCharacter = "\r\n";
Into:
private $newLineCharacter = PHP_EOL;
Cheers,
Mikael
Hi, I use " php artisan iseed my_table " but only get
`<?php
use Illuminate\Database\Seeder;
class my_tableTableSeeder extends Seeder
{
/**
* Auto generated seed file
*
* @return void
*/
public function run()
{
\DB::table('my_table')->delete();
}
}
`
please help
thanks
I have a postal code table with 700000 rows. Using this command returns nothing and no file is generated.
php artisan iseed postal_codes --force
Hi guys,
Is there a way to do laravel iseed reverse seeding without using table names? just the database parameters will do
Can someone make a switch or command that enables you to create a seed file for ALL tables in a database with a single command (except for the migrations table maybe)? I'm attempting to do this myself but I'm too much of a programming noob to get it yet.
Say, for example: $php artisan iseed:all
I know this isn't really an "issue" or a bug, but I didn't know where to request this.
Thanks
This is a really useful tool, its not a huge problem for me as I have my seed files in a repository, but an existing seed file was overwritten without warning when run from artisan. A prompt or an overwrite flag would be even better.
I created a seed from a table with 14 columns and over 5000 rows but when I ran "php artisan db:seed", I got a general error: 1390 prepared statement contains too many placeholders.
I edited the seed code to make two inserts instead of seeding all of the rows in one and then it worked.
\DB::table('users')->insert(array (
Laravel 5.4, here is my composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"type": "project",
"minimum-stability": "dev",
"require": {
"php": ">=5.6.4",
"doctrine/dbal": "^2.5",
"laracasts/utilities": ">=2.1",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"league/flysystem": ">=1.0.37",
"orangehill/iseed": "dev-master",
"predis/predis": "^1.1",
"talyssonoc/react-laravel": "dev-master",
"tcg/voyager": "dev-master"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.3",
"fzaninotto/faker": "~1.4",
"laravel/homestead": "^5.1",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7",
"phpspec/phpspec": "^3.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"LinguobotAdmin\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize",
"echo 'Change .env file credentials to your environment, so database and caching connections would work'"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan ide-helper:generate",
"php artisan ide-helper:meta",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
Hi everyone!
Laravel 5.3 is around the corner and this package needs some changes to work with it.
See the getData() method:
/**
* Get the Data
* @param string $table
* @return Array
*/
public function getData($table, $max)
{
if (!$max) {
return \DB::connection($this->databaseName)->table($table)->get();
}
return \DB::connection($this->databaseName)->table($table)->limit($max)->get();
}
Prior to L5.3 this method returns an array but in L5.3+ it returns a Collection that needs to be casted as an array.
Dirty quick fix to allow this package to work with both L5.3 and prior versions.
/**
* Repacks data read from the database
* @param array|object $data
* @return array
*/
public function repackSeedData($data)
{
// Check if $data is an array
if (!is_array($data)) {
$data = $data->toArray();
}
$dataArray = array();
if (is_array($data)) {
foreach ($data as $row) {
$rowArray = array();
foreach ($row as $columnName => $columnValue) {
$rowArray[$columnName] = $columnValue;
}
$dataArray[] = $rowArray;
}
}
return $dataArray;
}
Cheers
This will help avoid problems like #66, thanks.
We receive this error while doing composer update
Error Output: PHP Fatal error: Call to undefined method Illuminate\Foundation\Application::configPath() in /home/muthu/project/xport/server/vendor/orangehill/iseed/src
/Orangehill/Iseed/IseedServiceProvider.php on line 67
Is it possible to generate seeder data in more compact format?
For example now, table with 20k rows(US cities coordinates) size in iseed format is 5.7Mb, but in SQL dump format it takes just 1Mb, gzipped SQL dump - just 0.35Mb.
Hi, we were using this iseed perfectly with 5.3 now its not working with 5.4
when I run this
php artisan iseed product_types
I get this as an error
Segmentation fault: 11
https://github.com/orangehill/iseed/blob/master/src/Orangehill/Iseed/Iseed.php#L273
I store yml file in database, after export all structure be fail.
Why ltrim?
You should really put the "Composer Update" part before the part to include the Service provider... if the provider has already been added to the Config before calling "Composer Update" you will get an error.
Hello everyone.
My question is, can iseed be used as a backup of the information from a table? For example, I want to do regular backup of a table data in seed format every day or maybe every week automatically and without overriding the old seeders. Is there a way to do that?
Is it possible to add some tags to the current repo - I wan't to lock in my versioning? I.e. current build could be 1.1.0
Hi, I got a exception when install iseed for Laravel 5:
[RuntimeException]
Could not scan for classes inside "/home/vagrant/Code/rsct/vendor/orangehill/iseed/src/Orangehill/Iseed/Exceptions.php" which does not appear to be a file nor a folder
I'm not clear what's the reason, please help me out, thanks!
Support for installation on Laravel 4.1
Sqlite requires that the index name is unique database-wide. We could add a flag to prepend the table name for the sake of uniqueness to each id when converting from say, MySQL to Sqlite (for migrations and seeding used in testing).
- orangehill/iseed dev-master requires illuminate/support ~5.3.8 -> satisfiable by laravel/framework[v5.3.28], illuminate/support[v5.3.16, v5.3.23].
- orangehill/iseed dev-master requires illuminate/support ~5.3.8 -> satisfiable by laravel/framework[v5.3.28], illuminate/support[v5.3.16, v5.3.23].
- don't install laravel/framework v5.4.0|don't install illuminate/support v5.3.16
- don't install laravel/framework v5.4.0|don't install illuminate/support v5.3.23
- Can only install one of: laravel/framework[v5.4.0, v5.3.28].
- Installation request for laravel/framework 5.4.* -> satisfiable by laravel/framework[v5.4.0].
- Installation request for orangehill/iseed dev-master -> satisfiable by orangehill/iseed[dev-master].
Hi, could you please make this package avaible to use with laravel 5.
Sorry, i don`t speak english )
Can make it in the config?
After trying out this I got the following error:
Class TablenameTableSeeder does not exist
I'm trying to export from one environment to another. Should iseed be installed on the new environment also?
Hello,
I just tested your package and saves alot of work. thanks! ;)
meanwhile i've detected 1 issue and have another suggestion:
1st in seed.stub use \DB::table('{{table}}')->truncate(); instead of \DB::table('{{table}}')->delete();
delete() does not reset the autoincrements fields and there is no need to save undo states. truncate is faster (I use truncate because i do reset all database at once on every migrate:refresh).
in iseed.php you have:
if(strpos($content, '$this->call('UsersTableSeeder')')===false)
$content = preg_replace("/(run().+?)}/us", "$1\t$this->call('{$className}');\n\t}", $content);
should be
if(strpos($content, "$this->call('{$className}')")===false)
$content = preg_replace("/(run().+?)}/us", "$1\t$this->call('{$className}');\n\t}", $content);
without this you are allways adding same class to DatabaseSeeder.php
Sequence counter is not incrementing.
Laravel 5.4, Postgresql 9.5.
I have 50 tables I need to generate seeds for, it'd be fantastic if this tool accepted a comma delimited list of table names.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.