go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.17k stars 3.88k forks source link

built-in seeding functionality #5339

Closed TheMagicNacho closed 1 year ago

TheMagicNacho commented 2 years ago

Describe the feature

I am proposing that Gorm has a built in Seeding method so that developers can quickly seed databases within gorm without having to re-create the functionality.

Example Proposed Usage:


// make class (or interface) that is the same shape as your database
type person struct {
    name string
    age  int
}

// create an array of 'dummy' data using the object 
seedArray := [3]person{
    {
        name: "John Doe",
        age: 18
    },
    {
        name: "Jane Doe",
        age: 22
    },
    {
        name: "Steve Doe",
        age: 32
    }
}

// pass the array into a seeding method
DB.Seed(seedSlice)

Motivation

Seeding is a required process during the development process, and during platform migrations. Creating a seeding method will improve the developer's quality of life, and could increase the user-ship of GORM and GoLang as a whole.

Related Issues

Developers have asked if the functionality exists.

Issue 5274

Issue 1539

Some Developers have written Work around Tutorials

Tutorial

Chaostheorie commented 2 years ago

This sounds like functionality that should be done in a separate library and not as part of an ORM. Maybe an integration of the existing projects for seeding, like jaswdr/faker, with gorm, similar to datatypes, might be a better fit instead.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days

saeidee commented 1 year ago

Seeding seems to not be the responsibility of ORM, however, feel free to implement it as a plugin. https://gorm.io/docs/write_plugins.html