Search code examples
phpdatabase-migrationphinx

Migration call a seeder before executing next migration


Using the Phinx there is a way to a specific migration call a seeder before the next migration?

Any way to programmatically call a seeder inside a migration?


Solution

  • Not sure if the best way, but a solved the problem creating another PHP script who instantiated the Phinx classes and call the migrations and seeds conform needed.

    $pdo = new PDO($configs['db']['dsn'], $configs['db']['username'], $configs['db']['password'], [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
    ]);
    $config = new Config($configArray);
    $manager = new Manager($config, new S
    
    $config = new Config($configArray);
    $manager = new Manager($config, new StringInput(' '), new ConsoleOutput());
    
    $manager->migrate($environment, 20170825142637);
    $manager->seed($environment, 'UserSeeder');
    $manager->migrate($environment, 20170929000000);
    $manager->seed($environment, 'ProductSeeder');
    $manager->migrate($environment);