doctrine / migrations

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

Ask for a namespace of when more one path #1414

Closed Myks92 closed 2 months ago

Myks92 commented 4 months ago
Q A
Type improvement
BC Break no
Fixed issues no

Summary

When using multiple namespaces with Doctrine Migrations, the first one is selected by default. However, I suggest using an interactive namespace selection mode. This can be very convenient in situations where you have several databases within a modular monolithic application, where the migrations are located in each module.

The improvement affects three a commands:

Example

Global config

# config/packages/doctrine_migrations.yaml

doctrine_migrations:
    migrations_paths:
        'App\Migration': '%kernel.project_dir%/migrations'
    enable_profiler: '%kernel.debug%'
    organize_migrations: BY_YEAR

Modules

// src/Auth/config.php
<?php

declare(strict_types=1);

namespace App\Auth;

return static function (ContainerConfigurator $configurator): void {
    $configurator->extension('doctrine_migrations', [
        'migrations_paths' => [
            'App\\Auth\\Migration' => __DIR__ . '/Migration',
        ],
    ]);
};

Console

Run command without --no-interaction:

php bin/console doctrine:migrations:generate

Снимок экрана 2024-03-09 в 19 20 57

Generated new migration class to path app/src/Auth/Migration with namespace App\Auth\Migration

Run command with --no-interaction:

php bin/console doctrine:migrations:generate --no-interaction

Снимок экрана 2024-03-09 в 19 22 46

Generated new migration class to path app/migrations with namespace App\Migration

derrabus commented 3 months ago

Thank you. Please always write tests that cover your change.

Myks92 commented 3 months ago

Thanks for the comment. I have added tests.

Myks92 commented 3 months ago

@derrabus, what is missing for this PR to be approved?

derrabus commented 3 months ago

@derrabus, what is missing for this PR to be approved?

A green CI and a code review. I currently don't have time to conduct one, but maybe someone else does.

Myks92 commented 2 months ago

@derrabus, hi! Is there any time for code review? The CI errors are not related to my code. The error is in the file Db Migrator.php which I have not touched. I don't believe it is necessary for me to fix it, but I can if needed.

greg0ire commented 2 months ago

@Myks92 I addressed that issue for you :slightly_smiling_face:

Myks92 commented 2 months ago

@Myks92 I addressed that issue for you 🙂

Thank you for your help! I hope the PR will now be approved.

greg0ire commented 2 months ago

Thank you for your help! I hope the PR will now be approved.

Sorry to disappoint :grimacing: … but you're on the right track 👍

Myks92 commented 2 months ago

Sorry to disappoint 😬 … but you're on the right track 👍

Thanks for the reviews! I fixed it)

greg0ire commented 2 months ago

Please kindly squash your commits together. If you don't, we'll try to remember to do it for you but it's best if you save us this trouble.

How to do that?

  1. git rebase -i origin/3.8.x, assuming origin is a git remote that points to this repository, and not your fork. If you're not sure what your remotes are, run git remote -vvv, there should be your fork and the holy/reference/base/origin/whatever-you-call-it repository.
  2. A window will show up with many lines, replace pick with fixup on every line but the first one
  3. Close your editor, git should do its magic, and you should end up with one commit
  4. Use git push --force to overwrite what you already push. Don't forget the --force option otherwise git will try to merge both things together.
Myks92 commented 2 months ago

@greg0ire It's done!) I know how to do it. Thanks for the detailed instructions!)

greg0ire commented 2 months ago

It's a saved reply, so it's wasn't much effort :grin:

greg0ire commented 2 months ago

Thanks @Myks92 !