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

[DoctrineMigration] add the maker command for doctrine migration #10

Conversation

Simperfit
Copy link

I will add the test (need to switch room) later today.

}

$this->io->newLine();
$this->io->writeln(' <bg=green;fg=white> </>');
Copy link
Collaborator

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!');

Copy link
Author

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

Copy link
Member

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% :)

@Simperfit Simperfit force-pushed the feature/add-doctrine-migration-command branch from 2c6e82e to 4480565 Compare November 17, 2017 13:25
Copy link
Member

@weaverryan weaverryan left a 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 :)

{
$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')
Copy link
Member

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
{

}
Copy link
Member

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 :)

}

$this->io->newLine();
$this->io->writeln(' <bg=green;fg=white> </>');
Copy link
Member

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% :)

return [];
}

protected function execute(InputInterface $input, OutputInterface $output)
Copy link
Member

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() in AbstractCommand 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.

protected function configure()
{
$this
->setDescription('Creates a migration with the diff or an empty migration if there are no diffs')
Copy link
Member

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

Copy link
Collaborator

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)

Copy link
Member

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);
Copy link
Member

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.

Copy link
Author

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

Copy link
Contributor

@alcaeus alcaeus Nov 20, 2017

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>
Copy link
Member

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:
Copy link
Member

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.
Copy link
Member

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.

*/
final class MakeMigrationCommand extends AbstractCommand
{
protected static $defaultName = 'make:migrations';
Copy link
Member

Choose a reason for hiding this comment

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

make:migration

protected function configure()
{
$this
->setDescription('Creates a migration with the diff or an empty migration if there are no diffs')
Copy link
Member

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!

$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.')
Copy link
Member

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.

protected function writeNextStepsMessage(array $params, ConsoleStyle $io)
{
$io->text([
'Next: We just generated the migration',
Copy link
Member

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."

Copy link
Author

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 ?

{
$io->text([
'Next: We just generated the migration',
'Find the documentation at <fg=yellow>http://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.

Use https instead of http

$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'));
Copy link
Collaborator

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... 

throw new RuntimeCommandException(sprintf("Missing package%s: to use the migrations, run: \n\ncomposer require %s", 'migrations', 'migrations'));
}

if (true === $isEmpty) {
Copy link
Collaborator

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) {

Copy link
Author

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.

@Simperfit Simperfit force-pushed the feature/add-doctrine-migration-command branch from 4480565 to fcb9877 Compare November 20, 2017 06:28
@Simperfit
Copy link
Author

I think there is something wrong with the code, since I don't have any arguments and it expect me to have one

@Simperfit Simperfit changed the title [DoctrineMigration - WIP] add the maker command for doctrine migration [DoctrineMigration] add the maker command for doctrine migration Nov 20, 2017
@weaverryan
Copy link
Member

If/when this is merged, the official docs will need to be updated.

}
}

}
Copy link
Collaborator

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());

Copy link
Collaborator

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

@OskarStark
Copy link
Collaborator

We should activate fabot.io for this repository. Could you do this @weaverryan ?

@fabpot
Copy link
Member

fabpot commented Nov 24, 2017

@OskarStark fabbot activated for this repo.

@weaverryan
Copy link
Member

@Simperfit Can you rebase (sorry, I changed everything!) and look at the comments from @OskarStark?

@weaverryan
Copy link
Member

Replacing this with #97 - original commit included!

@weaverryan weaverryan closed this Dec 14, 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
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

6 participants