Skip to content

Comments

feat(java): support postgres URI forms for DATABASE_URL#369

Merged
davideme merged 1 commit intomainfrom
codex/database-url-jdbc-compat
Feb 13, 2026
Merged

feat(java): support postgres URI forms for DATABASE_URL#369
davideme merged 1 commit intomainfrom
codex/database-url-jdbc-compat

Conversation

@davideme
Copy link
Owner

Summary

  • add DATABASE_URL resolution logic in Java datasource config with explicit precedence
  • keep SPRING_DATASOURCE_URL behavior unchanged (used as-is when set)
  • normalize DATABASE_URL values for postgresql:// and postgres:// into JDBC URLs
  • add unit tests covering precedence and normalization scenarios
  • update Java application/docs examples for accepted DATABASE_URL formats

Testing

  • mvn -f src/java/pom.xml -Dtest=DataSourceConfigTest test (tests pass; build exits non-zero due to project-wide JaCoCo coverage gate when running only one class)
  • mvn -f src/java/pom.xml test (fails in this environment due to pre-existing Mockito/ByteBuddy self-attach issue unrelated to this change)

Copilot AI review requested due to automatic review settings February 13, 2026 09:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Java Spring Boot datasource configuration to accept DATABASE_URL in Postgres URI forms (postgresql:// and postgres://) by normalizing them into JDBC URLs, while preserving SPRING_DATASOURCE_URL behavior as a strict override used “as-is”.

Changes:

  • Add explicit precedence for URL resolution: SPRING_DATASOURCE_URL → normalized DATABASE_URLspring.datasource.url fallback.
  • Normalize DATABASE_URL values starting with postgresql:// or postgres:// into jdbc:postgresql://....
  • Add unit tests for precedence and basic normalization scenarios; update docs/examples to reflect accepted formats.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/java/src/main/java/org/openapitools/config/DataSourceConfig.java Adds URL resolution/normalization logic and updates Hikari configuration to use it.
src/java/src/test/java/org/openapitools/config/DataSourceConfigTest.java Expands unit tests to cover precedence and normalization behavior.
src/java/src/main/resources/application.properties Documents accepted DATABASE_URL formats and precedence.
src/java/README.md Updates setup examples to show postgresql://... and precedence notes.

Comment on lines +75 to +79
if (url.startsWith("postgresql://")) {
return "jdbc:" + url;
}
if (url.startsWith("postgres://")) {
return "jdbc:postgresql://" + url.substring("postgres://".length());
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

normalizeDatabaseUrl() currently only rewrites the URI scheme by prefixing/replacing strings. If DATABASE_URL is a full Postgres URI with userinfo (e.g. postgresql://user:pass@host:5432/db?sslmode=require), the resulting JDBC URL (jdbc:postgresql://user:pass@host:5432/db...) is not a valid PostgreSQL JDBC URL and will fail to connect. Consider parsing the URI (e.g., via java.net.URI) and constructing a proper jdbc:postgresql://host:port/db URL, mapping user/password into either Hikari username/password or query parameters, and preserving query params safely (including URL-decoding/encoding as needed).

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks for the review. This PR intentionally scopes compatibility to scheme normalization only (postgresql:// and postgres:// -> jdbc:postgresql://) for DATABASE_URL, while leaving SPRING_DATASOURCE_URL behavior unchanged. Handling full URI parsing (userinfo/query remapping) is a valid enhancement, but it is out of scope for this change and we can track it as a follow-up.

Comment on lines +32 to 44
void hikariConfig_ShouldNormalizeDatabaseUrlPostgresqlScheme() throws Exception {
DataSourceConfig config = new DataSourceConfig();

setField(config, "springDatasourceUrl", "");
setField(config, "databaseUrl", "postgresql://localhost:5432/lamp");
setField(config, "fallbackJdbcUrl", "jdbc:postgresql://localhost:5432/fallback");
setField(config, "username", "user");
setField(config, "password", "pass");
setField(config, "driverClassName", "org.postgresql.Driver");

HikariConfig result = config.hikariConfig();

assertThat(result.getJdbcUrl()).isEqualTo("jdbc:postgresql://localhost:5432/lamp");
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The new normalization tests cover scheme-only rewrites but don’t cover the most common DATABASE_URL form that includes credentials and/or query params (e.g. postgres://user:pass@host:5432/db?sslmode=disable). Adding unit tests for these cases will prevent regressions once normalizeDatabaseUrl() is updated to produce valid JDBC URLs for full Postgres URIs.

Copilot generated this review using guidance from repository custom instructions.
Copy link
Owner Author

Choose a reason for hiding this comment

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

Agreed this would be useful once we broaden parsing behavior. For this PR we intentionally kept scope to scheme compatibility only, so tests cover that explicit contract (including precedence and passthrough behavior). I’m leaving full credential/query-param URI parsing and corresponding tests for a follow-up change.

@davideme davideme merged commit 6d163e5 into main Feb 13, 2026
10 checks passed
@davideme davideme deleted the codex/database-url-jdbc-compat branch February 13, 2026 10:03
davideme added a commit that referenced this pull request Feb 15, 2026
* feat(benchmarks): add cloud run single-instance k6 benchmark harness

* feat(benchmarks): add cloud run service mapping and mode switch hooks

* docs(benchmarks): document db seeding and gcp runner setup

* docs: add postgres startup variable matrix by implementation

* docs: refresh postgres startup variables after syncing main

* feat(csharp): support DATABASE_URL fallback for connection string (#367)

* feat(csharp): add DATABASE_URL fallback for postgres connection

* test(csharp): fix file provider in connection resolution tests

* chore(csharp): address PR review feedback

* feat(java): support postgres URI forms for DATABASE_URL (#369)

* docs(go): clarify DATABASE_URL accepts postgres and postgresql schemes (#368)

* docs(go): document DATABASE_URL support for postgresql scheme

* docs(go): address PR review comments on DB URL schemes

* refactor(benchmarks): address PR review comments

* docs(benchmarks): align pass setup with database-url mode switching

* docs: rewrite postgres setup guide for end users

* feat(benchmarks): resolve cloud run project from config by default

* feat(benchmarks): support skip-setup and config-based project env

* fix(benchmarks): retry precheck and continue on iteration failures

* feat(benchmarks): add fast benchmark config profile

* chore(benchmarks): enforce Cloud Run startup probe settings

* chore(benchmarks): set Cloud Run min instances to 0

* docs(benchmarks): add macOS caffeinate run commands

* feat(benchmarks): add cold-start appendix measurement

* fix(benchmarks): avoid content-type on bodyless requests (#370)
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.

1 participant