migrations icon indicating copy to clipboard operation
migrations copied to clipboard

Migration files are not reloaded

Open fabpico opened this issue 2 years ago • 3 comments

Version 3.5.5

In a Symfony command, I call Doctrine commands. I create a migrations file and immediately execute it.

$this->getApplication()->find('doctrine:migrations:diff')->run(new StringInput(''), $output);
// ...
$this->getApplication()->find('doctrine:migrations:execute')->run(new StringInput("versions $lastMigrationsClass"), $output);

I get

In MigrationClassNotFound.php line 15:
                                                                             
  Migration class "DoctrineMigrations\Version20230213092010" was not found?

But it works, when I run both commands separately over the terminal. Meaning each terminal request boots the console application form new.

I debugged and saw that the loaded migration files misses the new migration file, but it exists in the filesystem. I see that vendor/doctrine/migrations/lib/Doctrine/Migrations/FilesystemMigrationsRepository.php Loads the migration files only once.

    private function loadMigrationsFromDirectories(): void
    {
        $migrationDirectories = $this->migrationDirectories;

        if ($this->migrationsLoaded) {
            return;
        }

        $this->migrationsLoaded = true;

Why is this reload of migrations guarded by an early return? Can’t the migrations just be reloaded?

Current behavior

Migration files are not reloaded internally.

Expected behavior

Migration files should be reloaded internally.

fabpico avatar Feb 13 '23 09:02 fabpico

same problem.

sunchuo avatar Apr 14 '24 10:04 sunchuo

What's the use case for doing this over using doctrine:schema:update?

greg0ire avatar Apr 16 '24 20:04 greg0ire

As I wrote here: 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.

derrabus avatar Apr 16 '24 20:04 derrabus