Skip to content
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

[3.0.0-alpha1] Allow migrations_paths to contain config file-relative paths #312

Closed
d42ohpaz opened this issue Apr 6, 2020 · 7 comments · Fixed by #318
Closed

[3.0.0-alpha1] Allow migrations_paths to contain config file-relative paths #312

d42ohpaz opened this issue Apr 6, 2020 · 7 comments · Fixed by #318
Milestone

Comments

@d42ohpaz
Copy link

d42ohpaz commented Apr 6, 2020

This is both a bug report and/or a feature request for the 3.0 alpha version of this bundle:

Allow defining relative paths to the migrations folder so that it can be referenced from within bundles. It seems the most common use case is to use %kernel.root_path%/migrations, but from within a bundle that path would not work. It would be useful to be able to define a path similar to '../../Migrations' (relative to a config file defined in the bundle) to use as a migrations path.

If there is a better way to define bundle-specific migrations paths - without modifying the main application - I'm open to suggestion.

@goetas
Copy link
Member

goetas commented Apr 7, 2020

Probably a nicer way would be allowing something as the @Bundle syntax in the path as many other bundles do.

@emodric
Copy link

emodric commented Apr 8, 2020

Migration classes don't have to be stored inside the bundle, they can be anywhere within a Composer package, if coming from vendor folder, so @Bundle syntax wouldn't work there.

Issue is complicated further if you wish to run migrations from within the Composer package (e.g. on CI), where you don't have a Symfony app and just run the migrations manually.

Allowing paths relative to the configuration would help in both of these cases.

@goetas goetas added this to the 3.0.0 milestone Apr 10, 2020
@goetas
Copy link
Member

goetas commented Apr 12, 2020

As I know no symfony bundle implements "config file relative paths".... regarding the doctrine/migrations library, the paths are already relative to the config file...
Can you clarify better what is expected here?

@d42ohpaz
Copy link
Author

the paths are already relative to the config file

The paths are relative to the Finder class:

    protected function getRealPath(string $directory) : string
    {
        $dir = realpath($directory);

        if ($dir === false || ! is_dir($dir)) {
            throw InvalidDirectory::new($directory);
        }

        return $dir;
    }

Tracing it all back to Configuration::getMigrationsDirectory(), there is no modification of the directory passed into this method, other than to replace ['kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir'] with the container values, so the relative path (e.g., ../../Migrations) inherits the current directory of the Finder class (e.g., vendor/doctrine/migrations/lib/Doctrine/Migrations/Finder/../../Migrations) - which does not exist.

@d42ohpaz
Copy link
Author

The requested behavior would be that passing in a relative path should instead use the root where the config file is stored. So if my config is located in /Users/9ae8sdf76/Dev/my-bundle/Resources/config/doctrine-migrations.yaml, then using ../../Migrations should look like /Users/9ae8sdf76/Dev/my-bvundle/Resources/config/../../Migrations - which resolves to (using realpath()) /Users/9ae8sdf76/Dev/my-bundle/Migrations.

@emodric
Copy link

emodric commented Apr 14, 2020

I have just tested my config file with using --configuration in doctrine:migrations:migrate command (ref #311), and I have used a config relative path without issues:

The config file is at vendor/my/app/migrations/migrations.yaml and migrations are at vendor/my/app/migrations/Doctrine. The following works without issues:

migrations_paths:
    My\App: Doctrine

when running php bin/console doctrine:migrations:migrate --configuration=vendor/my/app/migrations/migrations.yaml

@goetas
Copy link
Member

goetas commented Apr 14, 2020

@9ae8sdf76 I think that you are confusing the bundle configurations and the library one.

The library configuration is relative to the configuration file, the bundle is relative to the symfony working dir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants