doctrine / migrations

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

Migration files are not reloaded #1318

Open fabpico opened 1 year ago

fabpico commented 1 year ago

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.

sunchuo commented 3 months ago

same problem.

greg0ire commented 3 months ago

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

derrabus commented 3 months ago

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.