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

Make 'postgres print-command' quarkus command work with reactive datasources #27625

Merged
merged 1 commit into from Aug 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,6 +14,8 @@
@CommandDefinition(name = "print-command", description = "Outputs the psql command to connect to the database")
public class PsqlCommand implements Command {

private static final String JDBC_DATASOURCE__URL_KEY = "quarkus.datasource.jdbc.url";
private static final String REACTIVE_DATASOURCE__URL_KEY = "quarkus.datasource.reactive.url";
private final DevServicesLauncherConfigResultBuildItem devServicesLauncherConfigResultBuildItem;

public PsqlCommand(DevServicesLauncherConfigResultBuildItem devServicesLauncherConfigResultBuildItem) {
Expand All @@ -24,14 +26,25 @@ public PsqlCommand(DevServicesLauncherConfigResultBuildItem devServicesLauncherC
public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
//todo: should this work for non-dev services stuff as well? What about non-default datasources
try {
URI url = new URI(
devServicesLauncherConfigResultBuildItem.getConfig().get("quarkus.datasource.jdbc.url").substring(5));
int port = url.getPort();
String host = url.getHost();
URI uri;
if (devServicesLauncherConfigResultBuildItem.getConfig().containsKey(JDBC_DATASOURCE__URL_KEY)) {
uri = new URI(
devServicesLauncherConfigResultBuildItem.getConfig().get(JDBC_DATASOURCE__URL_KEY)
.substring("jdbc:".length()));
} else if (devServicesLauncherConfigResultBuildItem.getConfig().containsKey(REACTIVE_DATASOURCE__URL_KEY)) {
uri = new URI(
devServicesLauncherConfigResultBuildItem.getConfig().get(REACTIVE_DATASOURCE__URL_KEY)
.substring("vertx-reactive:".length()));
} else {
throw new RuntimeException("Unable to determine datasource URL");
}

int port = uri.getPort();
String host = uri.getHost();
String pw = devServicesLauncherConfigResultBuildItem.getConfig().get("quarkus.datasource.password");
commandInvocation.println("PGPASSWORD=" + pw + " psql --host=" + host + " --port=" + port + " --username="
+ devServicesLauncherConfigResultBuildItem.getConfig().get("quarkus.datasource.username") + " "
+ url.getPath().substring(1));
+ uri.getPath().substring(1));
return CommandResult.SUCCESS;
} catch (URISyntaxException e) {
throw new RuntimeException(e);
Expand Down