What is and what is a Seeder for?

5

I saw in% w_of% that there is a folder named Laravel . In it we have migrations and seeds.

I understand that migrations are migrations, they are codes that provide specifications for creating the tables in the database, without the need to know the SGDB that you want to use.

But what would this database or seeder ?

Is this Seeder name any programming concept, or something related to the database?

Is it directly related to migrations?

Note : Remembering that the question is not about Laravel, but about the explanation about the name Seeder or Seed that appears there.

    
asked by anonymous 04.05.2016 / 17:01

2 answers

3

But what would this seeder or seed be?

This is nothing more than pre-determined data that will be inserted into the database at startup.

Is it directly related to migrations?

Not with migrations per se, but rather with the concept of "Code First", that is, where you create your database according to the data model that your application has.

And when should I use?

This concept is widely used in testing, but is not limited to testing. A good example is when you need to create a user whenever you "install" your system in a new environment. Instead of creating a user at hand, you can set up a seed user and password that will be automatically entered into the system, simple? Another example would be data in tables that will populate combobox , cities / states, among many other examples.

A little bit of focus ...

You've commented on larável, but I'll put an example with the Entity Framework here.

public class SchoolDBInitializer : DropCreateDatabaseAlways<SchoolDBContext>
{
    protected override void Seed(SchoolDBContext context)
    {
        var user = new User{Name = "Admin", Password = "Admin"};
        context.Users.Add(user );
        base.Seed(context);
    }
}

In this example, every time the database is initialized by the code, the Admin user is inserted into the database.

    
05.05.2016 / 21:11
2

Seed is the concept of "feeding" your application with test data. In Laravel, Seeders classes are responsible for entering test data into your application.

    
04.05.2016 / 17:10