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

Update MigrateCommand.php #1028

Merged
merged 10 commits into from
Jul 6, 2020
Merged

Update MigrateCommand.php #1028

merged 10 commits into from
Jul 6, 2020

Conversation

ThomasLandauer
Copy link
Contributor

Q A
Type improvement
BC Break no
Fixed issues none

Summary

Adding the name of the database to CLI's yes/no question, analogous to https://github.com/doctrine/DoctrineFixturesBundle/blob/master/Command/LoadDataFixturesDoctrineCommand.php#L103

TODO: Do the same in ExecuteCommand and RollupCommand

Adding the name of the database to CLI's yes/no question, analogous to https://github.com/doctrine/DoctrineFixturesBundle/blob/master/Command/LoadDataFixturesDoctrineCommand.php#L103

TODO: Do the same in `ExecuteCommand` and `RollupCommand`
@@ -121,7 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
$migratorConfigurationFactory = $this->getDependencyFactory()->getConsoleInputMigratorConfigurationFactory();
$migratorConfiguration = $migratorConfigurationFactory->getMigratorConfiguration($input);

$question = 'WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue?';
$question = sprintf('WARNING! You are about to execute a migration in database "%s" that could result in schema changes and data loss. Are you sure you wish to continue?', $this->getDependencyFactory()->getConnection()->getDatabase());
Copy link
Member

Choose a reason for hiding this comment

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

getDatabase is not part of the \Doctrine\DBAL\Driver\Connection interface, thus i'm not sure if we can do this...

@greg0ire ?

Copy link
Member

Choose a reason for hiding this comment

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

🤔 but getConnection returns a \Doctrine\DBAL\Connection instead of that interface, right?

Copy link
Member

Choose a reason for hiding this comment

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

hmm. right. being so, we know the database... (i remember that there was a reason for choosing the concrete implementation, but can't recall why :-( )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In doctrine/migrations 2.2.1 I'm getting:

In MigrateCommand.php line 151:
Attempted to call an undefined method named "getDependencyFactory" of class "Doctrine\Bundle\MigrationsBundle\Command\MigrationsMigrateDoctrineCommand". Did you mean to call "setDependencyFactory"?

But in 3.0.1 get_class($this->getDependencyFactory()->getConnection()) gives me:

Doctrine\DBAL\Connection

Copy link
Member

Choose a reason for hiding this comment

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

the command getDependencyFactory has been introduced in 3.0

Copy link
Member

@goetas goetas Jun 28, 2020

Choose a reason for hiding this comment

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

@greg0ire I'm not sure if is worth this, it would be nice to change the return type from \Doctrine\DBAL\Driver\Connection to \Doctrine\DBAL\Connection to have a more simple interface

Copy link
Member

Choose a reason for hiding this comment

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

That wouldn't be a BC break, except for extending classes, so… go ahead?

Copy link
Member

Choose a reason for hiding this comment

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

May be I'm worrying too much. Probably the improved dx is worth this change.

@ThomasLandauer can you do the same change on the other commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done :-) (I just copied it over - since they all extend DoctrineCommand)

@goetas: What means "DX"? Developer Experience - as opposed to User Experience (UX)?

Copy link
Member

Choose a reason for hiding this comment

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

@ThomasLandauer yes, DX means Developer Experience

@goetas
Copy link
Member

goetas commented Jun 29, 2020

@ThomasLandauer tests are failing

Sqlite database name is empty.... what should we put in that case? the DB path? (is it possible with the current DBAL api?

@ThomasLandauer
Copy link
Contributor Author

Hm, could it be that the failure is an artifact of your testing environment? Cause I am getting the full path to my .sqlite file! (same as in fixtures bundle)...

ThomasLandauer and others added 3 commits June 29, 2020 22:15
Co-authored-by: Grégoire Paris <postmaster@greg0ire.fr>
Co-authored-by: Grégoire Paris <postmaster@greg0ire.fr>
Co-authored-by: Grégoire Paris <postmaster@greg0ire.fr>
@greg0ire greg0ire closed this Jul 1, 2020
@greg0ire greg0ire reopened this Jul 1, 2020
@goetas
Copy link
Member

goetas commented Jul 2, 2020

Tests are failing with a message as
You are about to execute a migration in database "" that could result in schema changes and data loss
As I was saying in one of my previous comments, for SQLite (with in-memory storage option) the database name seems to be empty)

@ThomasLandauer
Copy link
Contributor Author

OK, I see. So what should we do in that case? Display some constant string, e.g. "SQLite :memory:"? It looks like FixturesBundle isn't doing anything special, so it's probably also just showing "": https://github.com/doctrine/DoctrineFixturesBundle/blob/master/Command/LoadDataFixturesDoctrineCommand.php#L103

@goetas
Copy link
Member

goetas commented Jul 2, 2020

@ThomasLandauer what about $this->getDependencyFactory()->getConnection()->getDatabase() ?? 'unknown' ?

@ThomasLandauer
Copy link
Contributor Author

I changed it to ?? '<unnamed>', to emphasize that this is not an error but the database just doesn't have a "name". The tests will probably still fail, since they expect another string. Should I go ahead and adjust them?

@goetas
Copy link
Member

goetas commented Jul 3, 2020

@ThomasLandauer i'm fine with <unnamed>, can you please update the tests then?

@ThomasLandauer
Copy link
Contributor Author

Done :-) BTW: I only updated MigrateCommandTest.php; there seem to be no tests for the other two commands.

@goetas goetas requested a review from greg0ire July 4, 2020 08:37
@goetas
Copy link
Member

goetas commented Jul 4, 2020

@greg0ire I guess that for this we can do squash merge

@greg0ire greg0ire merged commit a864981 into doctrine:3.0.x Jul 6, 2020
@greg0ire
Copy link
Member

greg0ire commented Jul 6, 2020

Sure! Done.

@ThomasLandauer ThomasLandauer deleted the patch-1 branch July 7, 2020 05:57
@alcaeus alcaeus added this to the 3.0.2 milestone Dec 23, 2020
ThomasLandauer added a commit to ThomasLandauer/DoctrineFixturesBundle that referenced this pull request Nov 11, 2021
Since DBAL 3.0 (see doctrine/migrations#1028), the message currently reads for SQLite:
> Careful, database "" will be purged. Do you want to continue? (yes/no)

Neither @Ocramius (see doctrine/dbal#3606 (comment)) nor me (see doctrine/dbal#4982) succeeded in convincing @morozov to continue returning the file path ;-) So it looks like the fix needs to be done here...

Suggestion: What about adding the platform too? So the message would be:
> Careful, MySQL database "foo" will be purged. Do you want to continue? (yes/no)

`doctrine/migrations` is currently broken too:

> WARNING! You are about to execute a migration in database "<unnamed>" that could result in schema changes and data loss. Are you sure you wish to continue? (yes/no) [yes]:

So when done here, I'm going to submit the same there  (i.e. follow up of doctrine/migrations#1028)
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.

4 participants