Suggestion to add a seed()
A suggestion to add a seed() function that is defined inside any migration classes. If it exists, Phinx will run the seed() only after it runs up().
I often need this to seed tables with initial data, which goes along with migration.
:+1:
I'm currently using some create_<table>_defaults migration for each table that needs this.
Bonus points if phinx can migrate/rollback seeded rows!!
:+1:
I agree. Adding a functionality to create seed values will be great.
Separate seeds like laravel / rails would be great. What do you think @robmorgan ?
Sure, do you want to try contribute something?
Cheers,
Rob
On 18 Jun 2014, at 6:05 am, Todi Adiyatmo Wijoyo [email protected] wrote:
Separate seeds like laravel / rails would be great. What do you think @robmorgan ?
— Reply to this email directly or view it on GitHub.
All database connections in phinx is using AdapterInterface :
https://github.com/robmorgan/phinx/blob/0.3.x-dev/src/Phinx/Db/Adapter/AdapterInterface.php
The adapter interface enable the class to do anything with the table, it can addColumn , addIndex , etc. If we want implement a seeder, do you think it is better to divide the interface into 2 class ? Lets say BasicAdapterInterface and AdapterInterface so the adapter in the seeder has no access to table structure.
If its table specific then it might be better to put this functionality in the Table class. Tell me first how you would envisage to call it then we can find the best place for it?
e.g:
public function up()
{
$table = $this->table('something');
$table->seed(array('col1' = > 'somedata'));
}
What i mean is actualy i want to build new seed command like this
php phinx seed [ClassName] #default to DatabaseSeeder.php
So the seed will be separated from migration command. Each seed can call a seeder class or just run one class , for example :
class DatabaseSeeder extends Seeder
{
function run()
{
$user = $this->table('user');
$user->truncate();
$user->insert($data);
$this->calls('OtherSeeder');
}
}
Just like in http://laravel.com/docs/migrations#database-seeding
Ok this a bit more complex then, because you would need more commands to add, run and manage the seed functions.
Actually i've made the symfony console command to archive this in my project, if you interested to integrate this into phinx i can try to create the pull request.
Guys I've been thinking about this feature. For me its either a new method called seed() in each migration, Phinx can try to execute when migrating 'up'. It wouldn't handle removing data. There should be a flag to run to run it as well. We don't want this to happen in production.
The other method is more akin to the Rails way. I will introduce a new file(s) and commands. e.g: phinx seed. Which you can optionally run manually after migrating up first.
I'am voting for the separate seed comands, because more framework using it. Maybe it will be accepted better in community.
:+1: for the seed command
:+1: for seed command
:+1: for Seed command.
:+1: for seed command
:+1: for seed command
:+1: for seed command
:+1: the Rails way.
:+1: the Rails way.