-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Conversation
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()); |
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.
getDatabase
is not part of the \Doctrine\DBAL\Driver\Connection
interface, thus i'm not sure if we can do this...
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.
🤔 but getConnection
returns a \Doctrine\DBAL\Connection
instead of that interface, right?
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.
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 :-( )
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.
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
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 command getDependencyFactory
has been introduced in 3.0
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.
@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
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 wouldn't be a BC break, except for extending classes, so… go ahead?
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.
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?
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.
Sure, done :-) (I just copied it over - since they all extend DoctrineCommand
)
@goetas: What means "DX"? Developer Experience - as opposed to User Experience (UX)?
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.
@ThomasLandauer yes, DX means Developer Experience
@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? |
Hm, could it be that the failure is an artifact of your testing environment? Cause I am getting the full path to my |
lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php
Outdated
Show resolved
Hide resolved
lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php
Outdated
Show resolved
Hide resolved
lib/Doctrine/Migrations/Tools/Console/Command/RollupCommand.php
Outdated
Show resolved
Hide resolved
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>
Tests are failing with a message as |
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 |
@ThomasLandauer what about |
I changed it to |
@ThomasLandauer i'm fine with |
Done :-) BTW: I only updated |
@greg0ire I guess that for this we can do squash merge |
Sure! Done. |
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)
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
andRollupCommand