-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wiring up Migrations #44
Comments
Doctrine Migrations wants If you want to use <?php
declare(strict_types=1);
use Doctrine\Migrations\DependencyFactory;
$container = require __DIR__ . '/container.php';
return $container->get(DependencyFactory::class); With this approach command factories are not needed and not used. |
Thanks, @Xerkus I also noticed that. But I do need the ORM stuff (mostly for clearing cache). |
I totally agree. |
@rieschl did you find a better way to do this? I am using |
I use the First, I registered all factories as described here, then I created a wrapper for all the commands: declare(strict_types=1);
namespace App\Factory;
use Doctrine\Migrations\Tools\Console\Command\CurrentCommand;
use Doctrine\Migrations\Tools\Console\Command\DiffCommand;
use Doctrine\Migrations\Tools\Console\Command\DumpSchemaCommand;
use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand;
use Doctrine\Migrations\Tools\Console\Command\GenerateCommand;
use Doctrine\Migrations\Tools\Console\Command\LatestCommand;
use Doctrine\Migrations\Tools\Console\Command\ListCommand;
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand;
use Doctrine\Migrations\Tools\Console\Command\RollupCommand;
use Doctrine\Migrations\Tools\Console\Command\StatusCommand;
use Doctrine\Migrations\Tools\Console\Command\SyncMetadataCommand;
use Doctrine\Migrations\Tools\Console\Command\UpToDateCommand;
use Doctrine\Migrations\Tools\Console\Command\VersionCommand;
use Psr\Container\ContainerInterface;
final class MigrationsCommandsFactory
{
private ContainerInterface $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* @return list<object>
*/
public function create(): array
{
return [
$this->container->get(CurrentCommand::class),
$this->container->get(DiffCommand::class),
$this->container->get(DumpSchemaCommand::class),
$this->container->get(ExecuteCommand::class),
$this->container->get(GenerateCommand::class),
$this->container->get(LatestCommand::class),
$this->container->get(ListCommand::class),
$this->container->get(MigrateCommand::class),
$this->container->get(RollupCommand::class),
$this->container->get(SyncMetadataCommand::class),
$this->container->get(StatusCommand::class),
$this->container->get(UpToDateCommand::class),
$this->container->get(VersionCommand::class),
];
}
} in the $migrationCommands = $container->get(MigrationsCommandsFactory::class);
$commands = $migrationCommands->create(); The key point here is the All of that seems a bit verbose, considering both of them are doctrine packages. Having to register all commands manually is a bit flimsy (I had to check out the source of the migrations CLI to get all commands) and if a command is added, I have to add it manually in my cli-config. |
I just tried version 3 of this package which requires doctrine migrations v3 and it took me a while to figure out to correctly wire up the migrations CLI commands.
I added the factories as outlined in the docs (copy/paste from the
full-config
example) but to actually use the migration command I also had to add all migrations command to a$commands
array incli-config.php
, which seems to be an (undocumented?) feature of the Doctrine CLI.So, my question is... Did I do it wrong? If so, what is the correct way?
Should we add more documentation for this or is it obvious and I just didn't get it?
Also, should we add some possibilities to fetch the factory config and commands config (for CLI) from a helper? Searching for all possible Migrations commands is tedious.
When I was browsing the code I also noticed that the migrations stuff is neatly separated in a sub namespace, so maybe we could/should move the dependency from
require
to a suggestion for people who don't use migrations?Any opinions? Thanks!
The text was updated successfully, but these errors were encountered: