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
[DoctrineMigration] add the maker command for doctrine migration #10
[DoctrineMigration] add the maker command for doctrine migration #10
Conversation
src/Command/MakeMigrationCommand.php
Outdated
} | ||
|
||
$this->io->newLine(); | ||
$this->io->writeln(' <bg=green;fg=white> </>'); |
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 not?
$this->io->success('Success!');
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'm using the same format as the other commands, but why not I need to look
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.
iirc, this is just a way to have a little bit prettier format that $io->success()
, but I don't remember 100% :)
2c6e82e
to
4480565
Compare
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.
Thanks for taking this on! Very excited about it :)
src/Command/MakeMigrationCommand.php
Outdated
{ | ||
$this | ||
->setDescription('Creates a migration with the diff or an empty migration if there are no diffs') | ||
->addOption('empty', null, InputOption::VALUE_OPTIONAL, 'Generate an empty classes', 'false') |
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 be false
, not a string, right?
class MakeMigrationCommandTest extends TestCase | ||
{ | ||
|
||
} |
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.
We should add a test here: https://github.com/symfony/maker-bundle/blob/master/tests/Command/FunctionalTest.php#L68
And then we might not need a separate test at all :)
src/Command/MakeMigrationCommand.php
Outdated
} | ||
|
||
$this->io->newLine(); | ||
$this->io->writeln(' <bg=green;fg=white> </>'); |
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.
iirc, this is just a way to have a little bit prettier format that $io->success()
, but I don't remember 100% :)
src/Command/MakeMigrationCommand.php
Outdated
return []; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) |
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.
It's not really an intention for commands to override execute()
. I totally see why you did it though - this generator is a little bit different :). What about this:
-
Add a new
protected function generateCode()
inAbstractCommand
and put the$this->generator->generate()
code there by default. -
Override that method instead of
execute()
in this class.
Then we won't need to repeat things, like the success message at the bottom.
src/Command/MakeMigrationCommand.php
Outdated
protected function configure() | ||
{ | ||
$this | ||
->setDescription('Creates a migration with the diff or an empty migration if there are no diffs') |
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.
After some more thinking, I think we should not automatically create an empty migration if the diff is empty. Instead, we should show a message:
No changes were detected to your mapping metadata.
If you want to generate an empty migration, re-run the command with --empty
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.
or sth like this: make:migration --allow-empty
, make:migration:diff
(make::diff-migration
) or make:migration:empty
(make:empty-migration
)
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.
That looks too much and too complicated. Simplicity is the main feature of this bundle. Thanks!
|
||
if (true === $isEmpty) { | ||
$options['command'] = 'doctrine:migrations:diff'; | ||
$generateMigrationCommand->run(new ArgvInput($options), $output); |
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.
Is it possible to determine the new filename that was generated? I would love to repeat that in the "next steps" message.
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.
@alcaeus is it possible ? We may have talked about that but I can't remember
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.
Yes, we discussed it. The command doesn't return anything and I don't think it would be good for the command to keep the name of the last generated file in its state.
The only other option that comes to mind is actively parsing the output to grab the generated filename from the output.
@@ -0,0 +1,5 @@ | |||
The <info>%command.name%</info> command generates a new migrations: | |||
|
|||
<info>php %command.full_name% doctrine:migrations:migrate</info> |
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 be make:migration
@@ -0,0 +1,5 @@ | |||
The <info>%command.name%</info> command generates a new migrations: |
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.
migrations -> migration
|
||
<info>php %command.full_name% doctrine:migrations:migrate</info> | ||
|
||
If the argument is missing, the command will ask for the command name interactively. |
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.
not needed. But we should probably show one other example that shows the options being used.
src/Command/MakeMigrationCommand.php
Outdated
*/ | ||
final class MakeMigrationCommand extends AbstractCommand | ||
{ | ||
protected static $defaultName = 'make:migrations'; |
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.
make:migration
src/Command/MakeMigrationCommand.php
Outdated
protected function configure() | ||
{ | ||
$this | ||
->setDescription('Creates a migration with the diff or an empty migration if there are no diffs') |
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.
Do we really need all these options? Simplicity is the main feature of this bundle. Ideally commands have zero or one option. This looks too much to me ... but I don't use migrations, so please @weaverryan review the UX/DX of this command and see if we really need all these options. Thanks!
src/Command/MakeMigrationCommand.php
Outdated
$this | ||
->setDescription('Creates a migration with the diff or an empty migration if there are no diffs') | ||
->addOption('empty', null, InputOption::VALUE_OPTIONAL, 'Generate an empty classes', 'false') | ||
->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.
Dots at the end of each description (same below) should be removed.
src/Command/MakeMigrationCommand.php
Outdated
protected function writeNextStepsMessage(array $params, ConsoleStyle $io) | ||
{ | ||
$io->text([ | ||
'Next: We just generated the migration', |
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 We just generated the migration
should probably be removed with something along the lines of "Edit FILENAME to customize the migration."
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 can't have the filename since it just in the output, or is there something that i'm missing ?
src/Command/MakeMigrationCommand.php
Outdated
{ | ||
$io->text([ | ||
'Next: We just generated the migration', | ||
'Find the documentation at <fg=yellow>http://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.
Use https instead of http
src/Command/MakeMigrationCommand.php
Outdated
$diffMigrationCommand = $this->getApplication()->find('doctrine:migrations:diff'); | ||
$generateMigrationCommand = $this->getApplication()->find('doctrine:migrations:migrate'); | ||
} catch (CommandNotFoundException $e) { | ||
throw new RuntimeCommandException(sprintf("Missing package%s: to use the migrations, run: \n\ncomposer require %s", 'migrations', 'migrations')); |
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.
- Missing package%s: to use...
+ Missing package %s: to use...
src/Command/MakeMigrationCommand.php
Outdated
throw new RuntimeCommandException(sprintf("Missing package%s: to use the migrations, run: \n\ncomposer require %s", 'migrations', 'migrations')); | ||
} | ||
|
||
if (true === $isEmpty) { |
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.
is this needed?
- if (true === $isEmpty) {
+ if ($isEmpty) {
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 want it to be another type and equal to true.
4480565
to
fcb9877
Compare
I think there is something wrong with the code, since I don't have any arguments and it expect me to have one |
If/when this is merged, the official docs will need to be updated. |
} | ||
} | ||
|
||
} |
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.
EOF missing
|
||
$this->assertContains('Success', $tester->getDisplay()); | ||
$this->assertContains('Version', $tester->getDisplay()); | ||
|
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 remove this blank line
We should activate fabot.io for this repository. Could you do this @weaverryan ? |
@OskarStark fabbot activated for this repo. |
@Simperfit Can you rebase (sorry, I changed everything!) and look at the comments from @OskarStark? |
Replacing this with #97 - original commit included! |
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
I will add the test (need to switch room) later today.