-
-
Notifications
You must be signed in to change notification settings - Fork 400
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
New make:migration command #97
Conversation
src/Command/MakerCommand.php
Outdated
@@ -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')); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
src/Maker/MakeMigration.php
Outdated
{ | ||
$command | ||
->setDescription('Creates a new migration based on database changes.') | ||
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.') |
There was a problem hiding this comment.
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.
src/Maker/MakeMigration.php
Outdated
{ | ||
$command | ||
->setDescription('Creates a new migration based on database changes.') | ||
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.') |
There was a problem hiding this comment.
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.?
There was a problem hiding this comment.
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
src/Maker/MakeMigration.php
Outdated
|
||
public function getFiles(array $params): array | ||
{ | ||
return array(); |
There was a problem hiding this comment.
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!
src/Maker/MakeMigration.php
Outdated
{ | ||
$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</>', |
There was a problem hiding this comment.
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 ...
?
src/Maker/MakeMigration.php
Outdated
|
||
public function interact(InputInterface $input, ConsoleStyle $io, Command $command) | ||
{ | ||
} |
There was a problem hiding this comment.
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?
tests/Command/FunctionalTest.php
Outdated
new MakeMigration(), | ||
array( | ||
), | ||
); |
There was a problem hiding this comment.
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 👍
6034b95
to
2e9ef44
Compare
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. |
src/Maker/MakeMigration.php
Outdated
'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.', |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoooops :)
b18bf6b
to
b55fc62
Compare
b55fc62
to
95af9fa
Compare
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')) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.', |
There was a problem hiding this comment.
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.
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
This replaces #10.
There are 2 cases:
(A) When there ARE schema changes:
(B) When there are NOT schema changes:
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).