doctrine-migrations icon indicating copy to clipboard operation
doctrine-migrations copied to clipboard

You must provide either ManagerRegistry or ConnectionRegistry after an upgrade to 0.10.0

Open kostirez1 opened this issue 11 months ago • 5 comments

While trying to upgrade between 0.9.3 and 0.10.0, I encountered the following message:

ERROR: You must provide either ManagerRegistry or ConnectionRegistry.

Both $managerRegistry and $connectionRegistry values in DependencyFactoryCreator::create() are null, but I can't figure out why.

Compiled Nette DI container looks like:

public function createServiceNettrine__migrations__dependencyFactory(): Doctrine\Migrations\DependencyFactory
{
	return Nettrine\Migrations\DependencyFactoryCreator::create(
		$this,
		$this->getService('nettrine.migrations.configuration'),
		logger: $this->getService('monolog.logger.default'),
	);
}

config.neon options look ok to me, at least according to the documentation for 0.10.0.

nettrine.migrations:
  table: migrations
  directories:
      Foo\Bar\Migrations: %appDir%/../sql/migrations
  versionsOrganization: year_and_month
  customTemplate: %appDir%/../sql/migrations/migrations.tpl

Installed composer packages are:

Direct:
  doctrine/dbal: 3.9.4
  nettrine/dbal: 0.9.0
  nettrine/migrations: 0.10.0
Transitive:
  doctrine/cache: 2.2.0
  doctrine/deprecations: 1.1.4
  doctrine/event-manager: 2.0.1
  doctrine/migrations: 3.8.2
  nettrine/cache: 0.5.0

The two use Doctrine\Persistence\ConnectionRegistry and ManagerRegistry definitions don't resolve to anything, possibly due to doctrine/persistence not being installed? Although, even by requiring that, nothing changes. An upgrade of nettrine/dbal (0.9.0 -> 0.10.0) blocks due to my project still being on doctrine/dbal ^3.9.

Is it possible that nettrine/migrations v0.10.0 has some shadow/incorrect dependencies defined in composer.json? Thanks!

kostirez1 avatar Feb 01 '25 23:02 kostirez1

Thank you for your report. Do you think it would be possible to reproduce it here https://github.com/contributte/doctrine-skeleton ?

f3l1x avatar Feb 03 '25 11:02 f3l1x

Thanks for the quick reply. I will try to post a link to a modified branch, probably later this week.

kostirez1 avatar Feb 03 '25 22:02 kostirez1

Ping

f3l1x avatar Apr 14 '25 17:04 f3l1x

Thanks for your patience. This is what I've found by replicating it using the skeleton project.

This is how the DI container looks when everything is working. Notice how all of the nettrine.orm.managerRegistry references are linked to doctrine/orm in some way:

'Doctrine\Persistence\AbstractManagerRegistry' => [['nettrine.orm.managerRegistry']],
'Doctrine\Persistence\ConnectionRegistry' => [['nettrine.orm.managerRegistry']],
'Doctrine\Persistence\ManagerRegistry' => [['nettrine.orm.managerRegistry']],
'Nettrine\ORM\ManagerRegistry' => [['nettrine.orm.managerRegistry']],

public function createServiceNettrine__orm__managerRegistry(): Nettrine\ORM\ManagerRegistry
{
	return new Nettrine\ORM\ManagerRegistry(
		$this,
		[
		'default' => 'nettrine.dbal.connections.default.connection',
		'second' => 'nettrine.dbal.connections.second.connection',
	],
		[
		'default' => 'nettrine.orm.managers.default.entityManager',
		'second' => 'nettrine.orm.managers.second.entityManager',
	],
	);
}

public function createServiceNettrine__migrations__dependencyFactory(): Doctrine\Migrations\DependencyFactory
{
	return Nettrine\Migrations\DependencyFactoryCreator::create(
		$this,
		$this->getService('nettrine.migrations.configuration'),
		$this->getService('nettrine.orm.managerRegistry'),
		$this->getService('nettrine.orm.managerRegistry'),
	);
}

But once I removed nettrine/orm, nettrine/extra, nettrine/fixtures, doctrine/persistence and doctrine/orm, it broke the same way, just like in the other project.

Forked repository: https://github.com/kostirez1/doctrine-skeleton/commits/master/

# php bin/console 
Console Tool

Usage:
  command [options] [arguments]
...
In DependencyFactoryCreator.php line 46:
                                                                  
  You must provide either ManagerRegistry or ConnectionRegistry.

From what I understand, this just comes down to nettrine/migrations not knowing which connection to pass to doctrine/migrations. The only connection defined in my project is nettrine.dbal.connections.default, but I don't see a way to pass it there.

Perhaps DependencyFactoryCreator::create() could pass the default Connection object from nettrine/dbal directly into DependencyFactory::fromConnection() using the ExistingConnection? As opposed to using ConnectionRegistry.

kostirez1 avatar Apr 19 '25 21:04 kostirez1

Perhaps DependencyFactoryCreator::create() could pass the default Connection object from nettrine/dbal directly into DependencyFactory::fromConnection() using the ExistingConnection?

After quickly replacing throw new LogicalException() using the following:

$dependencyFactory = DependencyFactory::fromConnection(
	new ExistingConfiguration($configuration),
	new ExistingConnection($container->getService('nettrine.dbal.connections.default.connection')),
	$logger,
);

the commands seems to have started working again:

# php bin/console migrations:list
+-------------------------------------+--------------+-------------+----------------+-------------+
| Migration Versions                                                                |             |
+-------------------------------------+--------------+-------------+----------------+-------------+
| Migration                           | Status       | Migrated At | Execution Time | Description |
+-------------------------------------+--------------+-------------+----------------+-------------+
| DB\Migrations\Version20241212173845 | not migrated |             |                |             |
+-------------------------------------+--------------+-------------+----------------+-------------+

# php bin/console migrations:migrate
WARNING! You are about to execute a migration in database "demopostgres" that could result in schema changes and data loss. Are you sure you wish to continue? (yes/no) [yes]:
 > yes

[notice] Migrating up to DB\Migrations\Version20241212173845
[notice] finished in 11.6ms, used 8M memory, 1 migrations executed, 1 sql queries

[OK] Successfully migrated to version: DB\Migrations\Version20241212173845

kostirez1 avatar Apr 19 '25 22:04 kostirez1