A smart way of seeding tables in Laravel

Overview

SmartSeeder for Laravel

For Laravel 5, please use the 5.0 branch!

For Laravel 4, please use the 4.2 branch!

Seeding as it is currently done in Laravel is intended only for dev builds, but what if you're iteratively creating your database and want to constantly flush it and repopulate it during development? What if you want to seed a production database with different data from what you use in development? What if you want to seed a table you've added to a database that is currently in production with new data?

Features

  • Allows you to seed databases in different environments with different values.
  • Allows you to "version" seeds the same way that Laravel currently handles migrations. Running php artisan seed will only run seeds that haven't already been run.
  • Prompts you if your database is in production.
  • Allows you to run multiple seeds of the same model/table
  • Overrides Laravel's seeding commands. SmartSeeder will fire when you run
    php artisan db:seed
    
    or
    php artisan migrate:refresh --seed
    
  • You can run a single seed file with the --file option. php artisan seed:run --file=seed_2015_05_27_030017_UserSeeder

Use

When you install SmartSeeder, various artisan commands are made available to you which use the same methodology you're used to using with Migrations.

seed:run Runs all the seeds in the smartSeeds directory that haven't been run yet.
seed:make Makes a new seed class in the environment you specify.
seed:rollback Rollback doesn't undo seeding (which would be impossible with an auto-incrementing primary key). It just allows you to re-run the last batch of seeds.
seed:reset Resets all the seeds.
seed:refresh Resets and re-runs all seeds.
seed:install You don't have to use this... it will be run automatically when you call "seed"

Installation

  • Add require: "jlapp/smart-seeder": "dev-master" to your composer.json and run an update to bring it in (or run composer require jlapp/smartseeder).
  • Add 'Jlapp\SmartSeeder\SmartSeederServiceProvider' to your providers array in app/config/app.php
  • Run php artisan vendor:publish to push config files to your config folder if you want to override the name of the seeds folder or the name of the table where seeds are stored
Comments
  • [Feature Suggestion] Expand seeders to not be environment-specific

    [Feature Suggestion] Expand seeders to not be environment-specific

    We intended on using this package for one of our main applications, but we need seeders to run in all environments and it seems like the logic currently limits seeders to a specific environment. This makes it difficult for us to populate all of our environments with the seeded data without duplicating code. Is there something in the documentation I'm missing that allows us to have "global" seeders?

    opened by bkuhl 7
  • add path option through artisan command for seed location.

    add path option through artisan command for seed location.

    really nice package really easy way to create, run, install seeds i have check the code seeds path is define in config, can you add an option in package of providing path of the seed desire location, if that path options is not available then it can take config path. this will help other package developers to create new commands for creating seeds on other location they will call your commands with in their package commands no need to reinvent the wheel again,

    opened by umefarooq 6
  • failed to open stream: No such file or directory when seeding production

    failed to open stream: No such file or directory when seeding production

    This package is a great idea, but I am having issues getting it to work with production files.

    With the --env=production option, the package creates a seed file in the smartSeeds/production directory. However when I use the seed:run command, it does not find the file.

    Based on what I am seeing it is looking for the file in the root directory.

    /app/database/smartSeeds/someSeeder.php
    

    I even tried running the command like so seed:make --env=production but it's the same result.

    Anyone else experiencing this? Any suggestions?

    opened by marlongichie 5
  • Add option to specify a seed file to be run individually

    Add option to specify a seed file to be run individually

    By default, the seed:run command runs all the seed classes.

    However, it would be useful to be able to use the --class option to specify a specific seeder class to run individually. Much like the functionality provided by Laravel's out of the box seeding.

    This could look something like:

    php artisan seed:run --class=UserSeeder
    

    or

    php artisan seed:run --class=seed_2015_06_23_002940_UserSeeder
    
    opened by marlongichie 3
  • Fix namespace generated for DatabaseSeed stub

    Fix namespace generated for DatabaseSeed stub

    A seeder file generated for the stub still has backslash in the name space like namespace App\; which is invalid. I made the rtrim() strip the backslash instead which remove the last backslash. This fixed my issue.

    opened by mayppong 2
  • Allow user to specify path to the new seeder

    Allow user to specify path to the new seeder

    Use can specify php artisan seed:make --path={path from base_path()} to have their seed file created in that location. In the process, it will also create any intermediary folder along the way.

    opened by mayppong 1
  • 5.0 seed path

    5.0 seed path

    Add checking for the environment to the SeedMigrator.

    I had to do a few funny things to get this to work so it's more of a proof-of-concept. As it stands, the seed:make command will still generate a seeder that is namespaced. However, it won't be able to run with seed:run command until the user remove the namespace. Please do not approve this pull request as is.

    I was having problem getting it to migrate files in the folders named after the environment. It seems pretty straight forward in the resolve() function of the migrator. However, it turns out the runUp() wasn't using resolve() method neither did the discovering and invoking the seeder processes.

    When I tried to implement it on top of the namespace functionality, I was getting errors with it not being able to find the file. I decided to make as little change to the code as possible so I remove the namespacing from my seeders and that allows this code to work. It seems like the namespacing wasn't fully implemented yet and it was non-trivial to get going.

    Other things that I've explored:

    1. in getMigrationFiles(), I tried to preserved the environment name hoping that I wouldn't have to overwrite the requireFiles() function. That broke the instantiation of the class in migrator->resolve()
    2. I tried to resolved the file path the the environment in the seed commands rather than migrator but that also causes problem with the environment name being used as class name and wouldn't allow me to discover both files outside of the environment folder and inside of it. For example, it would be nice if both of the following files are loaded if local environment was specified.
    /database/smartSeeds/seeder_2015_01_01_vendors.php
    /database/smartSeeds/local/seeder_2015_01_01_vendors.php
    
    1. I wasn't able to instantiate the seeder with namespace for some reason. I'm not sure if there is something going on with the autoloader. In any case, it doesn't seem like Laravel's migration files generated has namespaces anyway so I'm not really sure what the intentions of supporting the namespace are. I'm leaving that up to you.

    Thanks!

    opened by mayppong 1
  • Up and Down methods for seeds like migrations

    Up and Down methods for seeds like migrations

    Hi,

    first of all big thank you for that package, this is what I'm looking for, but I see that after runing rollback nothink was changed in my db, the data is the same as before. So maybe seed classes should have two methods up and down like migrations has, so the developer can write what will happen when data is pushing to and pulling from db?

    When I run php artisan migrate:refresh --seed the second time then integrity constraint violations are thrown because the data still exists in db even if I run seed:rollback or seed:reset

    Is there any solution for that problem?

    opened by cve 1
  • Fix Laravel 5.1/5.2 composer.json errors

    Fix Laravel 5.1/5.2 composer.json errors

    This will fix the problems during the compsoer setup cause it just requiers any 5.* version and not a special 5.0.* one. Laravel tries to replace all the illuminate packages with it's self.version and this creates the confilcts.

    opened by Gummibeer 0
  • Change the default seedDir path

    Change the default seedDir path

    In Laravel 5, the database-related files have been moved to /database from the base path rather than in /app/database folder. Switch the seed migrator to look in the database file using database_path() as the base and change the config file to just smartSeeds instead.

    opened by mayppong 0
  • Error with env

    Error with env

    I'm creating a seeder this way:

    php artisan seed:make test --env=sprint-7

    but when I run:

    php artisan seed:run --env=sprint-7

    I get the following error:

    [Symfony\Component\Debug\Exception\FatalErrorException] Illuminate\Filesystem\Filesystem::requireOnce(): Failed opening required '/vagrant/database/smartSeeds/seed_2016_12_31_0_PagesTableSeeder.php' (include_path='.:/usr/share/php:/usr/share/pear')

    ps. I'm using the env parameter as a version instead of the real environment.

    opened by gm0re 0
  • 5.0 seed path

    5.0 seed path

    Add checking for the environment to the SeedMigrator.

    I had to do a few funny things to get this to work so it's more of a proof-of-concept. As it stands, the seed:make command will still generate a seeder that is namespaced. However, it won't be able to run with seed:run command until the user remove the namespace. Please do not approve this pull request as is.

    I was having problem getting it to migrate files in the folders named after the environment. It seems pretty straight forward in the resolve() function of the migrator. However, it turns out the runUp() wasn't using resolve() method neither did the discovering and invoking the seeder processes.

    When I tried to implement it on top of the namespace functionality, I was getting errors with it not being able to find the file. I decided to make as little change to the code as possible so I remove the namespacing from my seeders and that allows this code to work. It seems like the namespacing wasn't fully implemented yet and it was non-trivial to get going.

    Other things that I've explored:

    1. in getMigrationFiles(), I tried to preserved the environment name hoping that I wouldn't have to overwrite the requireFiles() function. That broke the instantiation of the class in migrator->resolve()
    2. I tried to resolved the file path the the environment in the seed commands rather than migrator but that also causes problem with the environment name being used as class name and wouldn't allow me to discover both files outside of the environment folder and inside of it. For example, it would be nice if both of the following files are loaded if local environment was specified.
    /database/smartSeeds/seeder_2015_01_01_vendors.php
    /database/smartSeeds/local/seeder_2015_01_01_vendors.php
    
    1. I wasn't able to instantiate the seeder with namespace for some reason. I'm not sure if there is something going on with the autoloader. In any case, it doesn't seem like Laravel's migration files generated has namespaces anyway so I'm not really sure what the intentions of supporting the namespace are. I'm leaving that up to you.

    Thanks!

    opened by mayppong 4
Owner
Jordan Lapp
Jordan Lapp
A Simple MVC PHP Framework, integrated with lot of features such as Session, Cookies, Migrations, Database, Factories, Seeding, Bootstrap and Tailwind CSS

Navite A Simple MVC PHP Framework, integrated with lot of features such as Session, Cookies, Migrations, Database, Factories, Seeding, Bootstrap and T

Celionatti 2 Aug 22, 2022
This packages enables the ability to serve file streams in a smart way

A blade component for easy image manipulation Want to serve private hosted images without the need to code your own logic ? Want to resize your images

Dieter Coopman 205 Dec 19, 2022
A set of PHP scripts which leverage MySQL INFORMATION_SCHEMA to create log tables and insert / update triggers

mysql-logtable-php mysql-logtable-php is a set of PHP scripts which leverage MySQL INFORMATION_SCHEMA to create log tables and insert / update trigger

null 3 Feb 27, 2022
BetterWPDB - Keeps you safe and sane when working with custom tables in WordPress.

BetterWPDB - Keeps you safe and sane when working with custom tables in WordPress.

Snicco 21 Dec 15, 2022
Symfony Bundle to create HTML tables with bootstrap-table for Doctrine Entities.

HelloBootstrapTableBundle This Bundle provides simple bootstrap-table configuration for your Doctrine Entities. Used bootstrap-table version 1.18.3. I

Sebastian B 7 Nov 3, 2022
Tables migrations seeded with data according to the Algerian education system structure.

Laravel algerian education system structure If you are building a Learning Management System or a School Management System and targeting the Algerian

Elaborate Code 12 Oct 8, 2022
Track your farming and pool performance on the Binance Smart Chain

farm.army - Frontend Track your farming and pool performance on the Binance Smart Chain. Tech Stack PHP 8 + Symfony node.js + npm (Webpack, Symfony en

farm.army 28 Sep 3, 2022
A proof-of-concept parser for the SMART Health Cards format.

SMART Health Cards parser A proof-of-concept parser for the SMART Health Cards format. This is not intended for production use. I just hacked this tog

Mikkel Paulson 55 Jul 31, 2022
Re-skinning BotCloaker enables you to add a SMART button at the end of all posts on your blog.

Re-skinning BotCloaker Wordpress Plugin Re-skinning BotCloaker enables you to add a SMART button at the end of all posts on your blog. Re-skinning Bot

Mohammed cha 120 Nov 11, 2022
Open Source Smart Meter with focus on privacy - you remain the master of your data.

volkszaehler.org volkszaehler.org is a free smart meter implementation with focus on data privacy. Demo demo.volkszaehler.org Quickstart The easiest w

volkszaehler.org project 176 Jan 4, 2023
Starless Sky is a network protocol for secure identities, providing the use of assymetric identities, public information, end-to-end messaging and smart contracts

Descentralized network protocol providing smart identity over an secure layer. What is the Starless Sky Protocol? Starless Sky is a network protocol f

Starless Sky Protocol 3 Jun 19, 2022
Smart File System - Use SmartFileInfo with useful methods that you need everyday

Smart File System - Use SmartFileInfo with useful methods that you need everyday

null 78 Dec 22, 2022
This project is based on the problem statement provided by the Minstry of HRD (India) for Smart India Hackathon '17.

This project is based on the problem statement provided by the Minstry of HRD (India) for Smart India Hackathon '17. As per the given problem statement, we need to solve the problem of bunching of marks at certain level, and problem of high scorers being at disadvantageous position due to lower competitive percentile.

Saransh Dave 4 Oct 13, 2022
MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query and get result in a fastest way

Mysql Optimizer mysql optimizer also known as MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query

null 2 Nov 20, 2021
Laravel Blog Package. Easiest way to add a blog to your Laravel website. A package which adds wordpress functionality to your website and is compatible with laravel 8.

Laravel Blog Have you worked with Wordpress? Developers call this package wordpress-like laravel blog. Give our package a Star to support us ⭐ ?? Inst

Binshops 279 Dec 28, 2022
The fastest way to make a powerful JSON:API compatible Rest API with Laravel.

The first fully customizable Laravel JSON:API builder. "CRUD" and protect your resources with 0 (zero) extra line of code. Installation You can instal

BinarCode 394 Dec 23, 2022
The easiest way to get started with event sourcing in Laravel

Event sourcing for Artisans ?? This package aims to be the entry point to get started with event sourcing in Laravel. It can help you with setting up

Spatie 591 Jan 4, 2023
My intention with this app is that new developers can have a concrete application with Laravel + VueJS where they can use it as example to learn the right way

My intention with this app is that new developers can have a concrete application with Laravel + VueJS where they can use it as example to learn the right way, implementing the best practices possible and at the same time learn how TDD is done. So this will be an example application but completely usable for any similar case.

Eng Hasan Hajjar 2 Sep 30, 2022
The only way to implement the pipe operator in PHP.

Pipe Operator in PHP Introduction This package is based on the pipe operator RFC by Sara Golemon and Marcelo Camargo (2016), who explains the problem

BoostPHP 21 Nov 12, 2022