RedBean Seeder (RedSeed?)
benmajor opened this issue · 6 comments
I am posting this more in order to generate a discussion than an actual issue with the framework, but it seems that GitHub has a more active community than the Google Group, so feel free to delete / close if out of scope or bounds.
I'm sure most of us are familiar with database seeding, and this is something that is supported in most modern PHP ORM implementations (both Eloquent and Doctrine provide this functionality, albeit with very different approaches). When developing a system using RedBean, I often find the need to generate new beans in order to test functionality, layout styling or something else, and to the best of my knowledge so far, there doesn't appear to be any system for seeding RedBean objects. Does the community think that it's a worthwhile exercise? If so, would this be something that is on the roadmap already for the project, or rather something that would be achieved through a plugin?
I would welcome any thoughts on the above, and am happy to be involved in development wherever necessary.
Hey @benmajor, this looks like a good discussion to have here if you ask me :)
There's seeds on one side (mandatory minimal data needed for an app/website to work) and fixtures on the other (fake test data) but I'll assume you are talking about a general system to populate a database, leaving the purpose aside.
There isn't anything to populate a database using RedBean in an automated way at the moment and as far as I'm concerned, it isn't on the roadmap. I'm not sure how this would integrate into RedBean though.
Did you already think about how you would like to see it implemented ? I'd be interested in hearing about it.
Thanks @Lynesth, and for your comments.
Indeed, I was talking about a general system to populate the database, rather than a specific purpose for the resulting data. Regarding the implementation, this is where I was hoping to create some discussion. Of course, one of the main advantages of using RedBean is for the automagic creation of tables. However, once that's been done, I think it would be nice to have some way of generating records or data.
I've been mulling over some thoughts for a while regarding this, but I don't know whether it would be suitable for the platform or not. Here's one thought that I had, which combines the standard RedBean syntax with the use of file a la Doctrine. For example, here's a proposed snippet for seeding 10 user
beans:
R::seed('user', 10, [
'forename' => 'string(5, 12)', # generates a random string between 5 and 12 chars long
'surname' => 'word(5, 12)', # generates a random word (sentence-cased) between 5 and 12 chars long
'email' => 'email()', # generates a random (verifiable) email address
'password' => 'password()' # generates a password (using the globally-defined hashing method
]);
This would then create 10 user
beans with the specified fields. The associative array is able to call a number of functions that are defined within the Seeder (for example password()
, etc).
In addition, we could also make use of the meta data to indicate that a bean has been seeded (rather than formally created), so we could similarly then easily remove any generated data using something like:
R::unseed('user');
I think this would be a great idea for a plug-in, but not for the core.
So I have managed to find a bit of time to give this some more thought, and have put together a very minimal proof-of-concept. Would appreciate your inputs:
Really nice work, added to plugin page: https://redbeanphp.com/index.php?p=/plugins#redseed
Thanks!
Thanks Gabor, I really appreciate your help and adding it to the list of available plugins.
I'll continue to work through and improve RedSeed, but to avoid any confusion I'll close this issue now.