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

Add command to ping the database #3697

Closed
wants to merge 1 commit into from
Closed

Conversation

mcfedr
Copy link

@mcfedr mcfedr commented Oct 15, 2019

Q A
Type feature
BC Break no

Summary

Adds a useful command to ping the database, it can do this in a loop to wait for it to be available.

Particularly useful when you want to run commands linked to docker containers, and you need to wait for the database to be up, and you don't have mysql client installed, plus its more useful than that because it uses your existing doctrine config and can connect to any database.

Also great for tests when you need to provision and spin up a db server on the fly.

@mcfedr mcfedr force-pushed the ping-command branch 2 times, most recently from e998f16 to 95473de Compare October 15, 2019 08:39
@mcfedr
Copy link
Author

mcfedr commented Oct 15, 2019

@greg0ire Commands shouldn't be final as they are wrapped in DoctrineBundle - this bundle also provides the arguments to allow connection switching.

@greg0ire
Copy link
Member

greg0ire commented Oct 15, 2019

@greg0ire Commands shouldn't be final as they are wrapped in DoctrineBundle - this bundle also provides the arguments to allow connection switching.

Would it be possible to do the wrapping using decoration? This could avoid issues with type declarations.

@mcfedr
Copy link
Author

mcfedr commented Oct 15, 2019

Would it be possible to do the wrapping using decoration?

I'm sure it would, but it seems outside of the scope of this PR, rather some refactoring to be done, first in DoctrineBundle, and then here with all the commands, and in the similar commands in ORM.

This could avoid issues with type declarations.

What issues?

@mcfedr
Copy link
Author

mcfedr commented Oct 17, 2019

@greg0ire I think all the issues have been addressed.

@greg0ire
Copy link
Member

This could avoid issues with type declarations.

Changes in type declarations in parent classes can be incompatible with the parent, and vice versa, and disappear if you use decoration.

For instance, phpunit has been adding the : void return type hint to TestCase::setUp lately, causing a lot of trouble in a big number of libraries (example: symfony/symfony#30071)

If you choose decoration, I would not require you to refactor the doctrine bundle and the dbal. Maybe documenting extension as a deprecated way of doing things in the project or as a github issue would be sufficient.

@mcfedr
Copy link
Author

mcfedr commented Oct 17, 2019

I'm just looking at what it would take to decorate this command in bundle, it feels like a much more brittle solution in this case - for example I'd have to get all the options, and maybe the (currently) empty arguments and recreate them - the only non-private parts of the command is the interface inherited from Command

@greg0ire
Copy link
Member

greg0ire commented Oct 17, 2019

Ok, if it's not straightforward let's stay with extension I guess. I think the command in the bundle will not be just about renaming this command and using a different description is it? Could you please open the PR on the bundle to show us how it will look like? I'm asking because setName and setDescription are public, which means we might be able to call them after instantiating the command (or using a constructor argument for the name)

} catch (Throwable $e) {
$output->writeln(sprintf('Connection error: <error>%s</error>', $e->getMessage()));

return 2;
Copy link
Member

Choose a reason for hiding this comment

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

What difference does it make for the caller? The ping either succeeded or didn't. Note that in DBAL v3, ping will throw an exception on failure, so it's not clear how this would have to be reimplemented w/o breaking the existing behavior.

Copy link
Author

Choose a reason for hiding this comment

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

It probably makes little difference to the caller, but as there are two different failures it doesnt do any hard to be more informative - note that this becomes the exit code from the process

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I've changed the text to just be 'ping failed', so it won't be misleading when DBAL 3 throws on different failure types - anyway the caught exception will say its a connection error or something else.

Copy link
Member

Choose a reason for hiding this comment

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

I still don't understand the meaning of the two different return codes and how they will be supported in 3.0.

lib/Doctrine/DBAL/Tools/Console/Command/PingCommand.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Tools/Console/Command/PingCommand.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Tools/Console/Command/PingCommand.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Tools/Console/Command/PingCommand.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Tools/Console/Command/PingCommand.php Outdated Show resolved Hide resolved
@mcfedr
Copy link
Author

mcfedr commented Oct 21, 2019

@greg0ire I've now opened doctrine/DoctrineBundle#1035 with the command added there.

@mcfedr mcfedr force-pushed the ping-command branch 3 times, most recently from dab0979 to 007119d Compare October 21, 2019 11:10
@mcfedr
Copy link
Author

mcfedr commented Oct 22, 2019

@greg0ire I think all is good now?

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

Yes, sorry!

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

Yes, sorry!

@mcfedr
Copy link
Author

mcfedr commented Oct 22, 2019

Yes, sorry!

No problem :)

Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

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

@mcfedr could you describe the difference between the 1 and 2 exit codes from the user perspective?

Base automatically changed from master to 4.0.x January 22, 2021 07:44
@morozov
Copy link
Member

morozov commented Jul 8, 2021

Pinging a database is no longer supported (#4128).

@morozov morozov closed this Jul 8, 2021
@morozov morozov added the Tools label Jul 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants