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

New make:migration command #97

Merged

Conversation

weaverryan
Copy link
Member

@weaverryan weaverryan commented Dec 14, 2017

This replaces #10.

There are 2 cases:

(A) When there ARE schema changes:

screen shot 2017-12-29 at 11 07 47 pm

(B) When there are NOT schema changes:

screen shot 2017-12-29 at 11 07 14 pm

This includes a BC break on MakerInterface, but it will only affect people who have created custom makers (and they'll get a clear error).

@@ -79,7 +82,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
continue;
}

$value = $this->io->ask($argument->getDescription(), $argument->getDefault(), [Validator::class, 'notBlank']);
$value = $this->io->ask($argument->getDescription(), $argument->getDefault(), array(Validator::class, 'notBlank'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, revert this change. We don't use the legacy array() notation in this bundle.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it's available since PHP 5.4. Anyone using this bundle will probably have at least 5.5 or 5.6

/**
* Called after normal code generation.
*
* @param ConsoleStyle $io
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PHPdoc is not needed because we use type-hints.

{
$command
->setDescription('Creates a new migration based on database changes.')
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove "...to use for this command" in all descriptions because it's redundant. Also, I'd like better descriptions. For example, this doesn't help me -> db = The database connection. I can't provide a database connection to a console command. Is this the name of the database connection? The name of the Doctrine database connection? etc.

{
$command
->setDescription('Creates a new migration based on database changes.')
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should all these options define default values for the common case where there's only 1 database, 1 em, etc.?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can already get the default connection from Doctrine, as well as for the entity manager, especially if you have only one connection


public function getFiles(array $params): array
{
return array();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More array() notation to replace by [] Thanks!

{
$io->text(array(
'Next: Edit Version(lastVersion) to customize the migration.',
'Find the documentation at <fg=yellow>https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html</>',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we standardize these doc links in all commands? Find the documentation at... looks too long to me. What about See ... ?


public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
{
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why implement interact when it's empty?

new MakeMigration(),
array(
),
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again please use short-syntax for arrays 👍

@weaverryan weaverryan force-pushed the feature/add-doctrine-migration-command branch 3 times, most recently from 6034b95 to 2e9ef44 Compare December 30, 2017 04:24
@weaverryan
Copy link
Member Author

This is ready to be reviewed :) - screenshots back in the original description. This also uses the new test system, which means there are real functional tests that actually run the commands and assert that the 2 outputs above occur.

'No database changes were detected.'
]);
$io->text([
'The database schema was compared with your mapping information and they are already in sync: there is no generation to migrate.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the "there is no generation to migrate." part :) I suppose it should be "there is no migration to generate."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoooops :)

@weaverryan weaverryan force-pushed the feature/add-doctrine-migration-command branch 7 times, most recently from b18bf6b to b55fc62 Compare December 30, 2017 19:21
@weaverryan weaverryan force-pushed the feature/add-doctrine-migration-command branch from b55fc62 to 95af9fa Compare December 30, 2017 19:30
@weaverryan
Copy link
Member Author

Comment addressed (and a few other things). Tests are passing, ready for a final review :).

And sorry for the noise in the diff: this command is a bit different, so we needed to expand the maker system a bit and also the tests, which affected some unrelated things.


public function writeSuccessMessage(array $params, ConsoleStyle $io)
{
if (false !== strpos($this->migrationOutput, 'No changes detected')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this logic because it looks fragile ... but there's no other possible way to detect if a migration was generated or not. If MigrationsBundle supported JSON as one of its output formats ... but it doesn't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're exactly right. So I'm depending on our tests to catch this :/

{
if (false !== strpos($this->migrationOutput, 'No changes detected')) {
$io->warning([
'No database changes were detected.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if we could reword the messages in case no migration is needed:

Before:

[WARNING] No database changes were detected.

The database schema was compared with your mapping information and they are
already in sync: no migration was generated.

After:

[WARNING] No migration was generated.

The database schema and the application mapping information are already in sync.

@weaverryan weaverryan merged commit f2e25e9 into symfony:master Dec 31, 2017
weaverryan added a commit that referenced this pull request Dec 31, 2017
This PR was squashed before being merged into the 1.0-dev branch (closes #97).

Discussion
----------

New make:migration command

This replaces #10.

There are 2 cases:

(A) When there ARE schema changes:

<img width="1053" alt="screen shot 2017-12-29 at 11 07 47 pm" src="https://user-images.githubusercontent.com/121003/34451290-9b0c9bb0-ecef-11e7-9a1d-41ba78c84638.png">

(B) When there are NOT schema changes:

<img width="1269" alt="screen shot 2017-12-29 at 11 07 14 pm" src="https://user-images.githubusercontent.com/121003/34451291-a617113e-ecef-11e7-979f-c30f2cc3e91e.png">

This includes a BC break on `MakerInterface`, but it will only affect people who have created custom makers (and they'll get a clear error).

Commits
-------

f2e25e9 tweaking message
95af9fa Adding make:migration, which includes reworking MakerInterface
@weaverryan weaverryan deleted the feature/add-doctrine-migration-command branch December 31, 2017 18:15
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 this pull request may close these issues.

None yet

4 participants