doctrine / migrations

Doctrine Database Migrations Library
https://www.doctrine-project.org/projects/migrations.html
MIT License
4.65k stars 387 forks source link

Error when running doctrine:migrations: 'diff' and 'migrate' at the same thread #1422

Closed sunchuo closed 2 months ago

sunchuo commented 2 months ago

Bug Report

Q A
BC Break no
Version 3.2

Summary

$makeMigrationCommand = $this->getApplication()->find('doctrine:migrations:diff');
$makeMigrationCommandInput = new ArgvInput(['--no-interaction' => true]);
$makeMigrationCommand->run($makeMigrationCommandInput, $output);

$listMigrationsCommand = $this->getApplication()->find('doctrine:migrations:list');
$listMigrationsCommandInput = new ArgvInput([]);
$listMigrationsCommand->run($listMigrationsCommandInput, $output);

$migrateCommand = $this->getApplication()->find('doctrine:migrations:migrate');
$migrateCommandInput = new ArgvInput(['--no-interaction' => true]);
$migrateCommandInput->setInteractive(false);
$migrateCommand->run($migrateCommandInput, $output);

output:


 Generated new migration class to "/skeleton/migrations/Version20240414110144.php"

 To run just this migration for testing purposes, you can use migrations:execute --up 'DoctrineMigrations\\Version20240414110144'

 To revert the migration you can use migrations:execute --down 'DoctrineMigrations\\Version20240414110144'

+-----------+--------+-------------+----------------+-------------+
| Migration Versions                                |             |
+-----------+--------+-------------+----------------+-------------+
| Migration | Status | Migrated At | Execution Time | Description |
+-----------+--------+-------------+----------------+-------------+

 [ERROR] The version "latest" couldn't be reached, there are no registered migrations.                                  

Current behavior

Generated migration files don't seem to be loaded. FilesystemMigrationsRepository::loadMigrationsFromDirectories is only run once or a new Version that has not been registered.

add code $this->getDependencyFactory()->getMigrationRepository()->registerMigration($fqcn); after DiffCommand.php#L152

then throw a MigrationClassNotFound Exception at FilesystemMigrationsRepository.php#L117

add "DoctrineMigrations\\": "migrations/" to composer.json

problem solved.

Expected behavior

All commands should think about being called in the same process. The DoctrineMigrations directory should be registered for autoloading.

derrabus commented 2 months ago

I'm not sure if this is an issue worth fixing. The generated migration is not meant to be executed immediately, but to be reviewed and adjusted by a human being.

That being said, you proposed fix sounds reasonable. Feel free to submit a PR.

greg0ire commented 2 months ago

@sunchuo if I may ask, why are you not using doctrine:schema:update?

greg0ire commented 2 months ago

Duplicate of #1318