Skip to content

Commit

Permalink
build(deps): bump org.postgresql:postgresql from 42.7.4 to 42.7.5 (#2750
Browse files Browse the repository at this point in the history
)

* build(deps): bump org.postgresql:postgresql from 42.7.4 to 42.7.5

Bumps [org.postgresql:postgresql](https://github.com/pgjdbc/pgjdbc) from 42.7.4 to 42.7.5.
- [Release notes](https://github.com/pgjdbc/pgjdbc/releases)
- [Changelog](https://github.com/pgjdbc/pgjdbc/blob/master/CHANGELOG.md)
- [Commits](pgjdbc/pgjdbc@REL42.7.4...REL42.7.5)

---
updated-dependencies:
- dependency-name: org.postgresql:postgresql
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* test: modify tests to fit new behavior of JDBC driver

The PostgreSQL JDBC driver partly reverted the changes they made in the
previous version for how application_name is set. application_name is now
no longer send as a Startup parameter, and instead always set using a SQL
statement.

See pgjdbc/pgjdbc@8912bbe

* test: add latest version to metadata test

* fix: replace metadata queries for 42.7.5

* test: fix rails detection

* test: remove schema dump

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Knut Olav Løite <[email protected]>
  • Loading branch information
dependabot[bot] and olavloite authored Jan 20, 2025
1 parent 77e44c1 commit 105b220
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 146 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.4</version>
<version>42.7.5</version>
</dependency>
<dependency>
<groupId>com.kohlschutter.junixsocket</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ static String replaceJdbcMetadataStatement(String sql) {
// with Spangres-compatible queries.
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_EXPORTED_IMPORTED_KEYS_PREFIX)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_EXPORTED_IMPORTED_KEYS_42_0_PREFIX)) {
return replaceImportedExportedKeysQuery(sql);
return replaceImportedExportedKeysQuery(
sql, PgJdbcCatalog.PG_JDBC_EXPORTED_IMPORTED_KEYS_REPLACEMENT, "KEY_SEQ");
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_EXPORTED_IMPORTED_KEYS_PREFIX_V42_7_5)) {
return replaceImportedExportedKeysQuery(
sql, PgJdbcCatalog.PG_JDBC_EXPORTED_IMPORTED_KEYS_REPLACEMENT_UPPER_CASE, "\"KEY_SEQ\"");
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_SCHEMAS_PREFIX)) {
return replaceGetSchemasQuery(sql);
return replaceGetSchemasQuery(sql, PgJdbcCatalog.PG_JDBC_GET_SCHEMAS_REPLACEMENT);
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_SCHEMAS_PREFIX_V42_7_5)) {
return replaceGetSchemasQuery(sql, PgJdbcCatalog.PG_JDBC_GET_SCHEMAS_REPLACEMENT_UPPER_CASE);
}
if (sql.contains(LiquibaseStatementHelper.TAG_STATEMENT_PART)) {
return LiquibaseStatementHelper.replaceTagStatement(sql);
Expand All @@ -65,10 +73,16 @@ static String replaceJdbcMetadataStatement(String sql) {
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_TABLES_PREFIX_5)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_TABLES_PREFIX_6)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_TABLES_PREFIX_7)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_TABLES_PREFIX_8)) {
return replaceGetTablesQuery(sql);
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_TABLES_PREFIX_8)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_TABLES_PREFIX_9)) {
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_TABLES_PREFIX_9)) {
return replaceGetTablesQuery(sql, PgJdbcCatalog.PG_JDBC_GET_TABLES_REPLACEMENT_UPPER_CASE);
} else {
return replaceGetTablesQuery(sql, PgJdbcCatalog.PG_JDBC_GET_TABLES_REPLACEMENT);
}
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_COLUMNS_PREFIX_1)
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_COLUMNS_PREFIX_V42_7_5)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_COLUMNS_PREFIX_1)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_COLUMNS_PREFIX_2)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_COLUMNS_PREFIX_3)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_COLUMNS_PREFIX_4)
Expand All @@ -78,39 +92,49 @@ static String replaceJdbcMetadataStatement(String sql) {
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_COLUMNS_PREFIX_4_1)) {
return replaceGetColumnsQuery(sql);
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_INDEXES_PREFIX_1)
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_INDEXES_PREFIX_V42_7_5)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_INDEXES_PREFIX_1)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_INDEXES_PREFIX_2)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_INDEXES_PREFIX_3)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_INDEXES_PREFIX_1_1)) {
return replaceGetIndexInfoQuery(sql);
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_PRIMARY_KEY_PREFIX_1)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_PRIMARY_KEY_PREFIX_2)) {
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_PRIMARY_KEY_PREFIX_2)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_PRIMARY_KEY_PREFIX_V42_7_5)) {
return replaceGetPrimaryKeyQuery(sql);
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_TABLE_PRIVILEGES_PREFIX_1)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_TABLE_PRIVILEGES_PREFIX_2)) {
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_TABLE_PRIVILEGES_PREFIX_2)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_TABLE_PRIVILEGES_PREFIX_3)) {
return PgJdbcCatalog.PG_JDBC_GET_TABLE_PRIVILEGES_REPLACEMENT;
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_COLUMN_PRIVILEGES_PREFIX_1)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_COLUMN_PRIVILEGES_PREFIX_1_1)) {
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_COLUMN_PRIVILEGES_PREFIX_1_1)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_COLUMN_PRIVILEGES_PREFIX_V42_7_5)) {
return PgJdbcCatalog.PG_JDBC_GET_TABLE_PRIVILEGES_REPLACEMENT;
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_BEST_ROW_IDENTIFIER_PREFIX)) {
return PgJdbcCatalog.PG_JDBC_GET_BEST_ROW_IDENTIFIER_REPLACEMENT;
}

if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_FUNCTIONS_WITH_FUNC_TYPE_PREFIX)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_FUNCTIONS_WITHOUT_FUNC_TYPE_PREFIX)) {
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_FUNCTIONS_WITHOUT_FUNC_TYPE_PREFIX)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_FUNCTIONS_UPPER_CASE_PREFIX)) {
return PgJdbcCatalog.PG_JDBC_GET_FUNCTIONS_REPLACEMENT;
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_FUNCTION_COLUMNS_PREFIX)) {
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_FUNCTION_COLUMNS_PREFIX)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_FUNCTION_COLUMNS_PREFIX_V42_7_5)) {
return PgJdbcCatalog.PG_JDBC_GET_FUNCTION_COLUMNS_REPLACEMENT;
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_PROCEDURES_PREFIX)) {
return PgJdbcCatalog.PG_JDBC_GET_PROCEDURES_REPLACEMENT;
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_UDTS_PREFIX)) {
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_PROCEDURES_PREFIX_V42_7_5)) {
return PgJdbcCatalog.PG_JDBC_GET_PROCEDURES_REPLACEMENT;
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_UDTS_PREFIX)
|| sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_UDTS_PREFIX_V42_7_5)) {
return PgJdbcCatalog.PG_JDBC_GET_UDTS_REPLACEMENT;
}
if (sql.startsWith(PgJdbcCatalog.PG_JDBC_GET_MAX_NAME_LENGTH_PREFIX)) {
Expand Down Expand Up @@ -204,8 +228,7 @@ private static String replacePG42_3_PkQuery_With_42_2_Query(String sql) {
return replacedSql + whereClause + " ORDER BY ct.relname, pk_name, key_seq";
}

private static String replaceGetSchemasQuery(String sql) {
String replacedSql = PgJdbcCatalog.PG_JDBC_GET_SCHEMAS_REPLACEMENT;
private static String replaceGetSchemasQuery(String sql, String replacedSql) {
int startIndex;
if (sql.contains(" AND nspname LIKE ")) {
startIndex = sql.indexOf(" AND nspname LIKE ");
Expand All @@ -218,8 +241,7 @@ private static String replaceGetSchemasQuery(String sql) {
.replace(" ORDER BY TABLE_SCHEM", " ORDER BY schema_name");
}

private static String replaceGetTablesQuery(String sql) {
String replacedSql = PgJdbcCatalog.PG_JDBC_GET_TABLES_REPLACEMENT;
private static String replaceGetTablesQuery(String sql, String replacedSql) {
int startIndex;
String wherePrefix = "WHERE c.relnamespace = n.oid";
if (sql.contains(wherePrefix)) {
Expand Down Expand Up @@ -344,6 +366,9 @@ private static String replaceGetIndexInfoQuery(String sql) {
.replace(" AND n.nspname = ", " AND IDX.TABLE_SCHEMA = ")
.replace(" AND ct.relname = ", " AND IDX.TABLE_NAME = ")
.replace(" AND i.indisunique ", " AND IDX.IS_UNIQUE='YES' ")
.replace(
") AS tmp ORDER BY \"NON_UNIQUE\", \"TYPE\", \"INDEX_NAME\", \"ORDINAL_POSITION\"",
" ORDER BY IDX.TABLE_NAME, IS_UNIQUE DESC, IDX.INDEX_NAME, CASE WHEN ORDINAL_POSITION IS NULL THEN 0 ELSE ORDINAL_POSITION END")
.replace(
") AS tmp ORDER BY NON_UNIQUE, TYPE, INDEX_NAME, ORDINAL_POSITION",
" ORDER BY IDX.TABLE_NAME, IS_UNIQUE DESC, IDX.INDEX_NAME, CASE WHEN ORDINAL_POSITION IS NULL THEN 0 ELSE ORDINAL_POSITION END")
Expand All @@ -364,6 +389,7 @@ private static String replaceGetPrimaryKeyQuery(String sql) {
replacedSql += " WHERE TRUE " + sql.substring(startIndex);
return replacedSql
.replace(") result where result.A_ATTNUM = (result.KEYS).x", "")
.replace("AND result.KEY_SEQ <= KEY_COUNT", "")
.replace(" AND n.nspname = ", " AND IDX.TABLE_SCHEMA = ")
.replace(" AND ct.relname = ", " AND IDX.TABLE_NAME = ")
.replace(" AND i.indisprimary ", " AND IDX.INDEX_TYPE='PRIMARY_KEY' ")
Expand All @@ -375,8 +401,8 @@ private static String replaceGetPrimaryKeyQuery(String sql) {
"ORDER BY COLS.TABLE_NAME, IDX.INDEX_NAME, COLS.ORDINAL_POSITION");
}

private static String replaceImportedExportedKeysQuery(String sql) {
String replacedSql = PgJdbcCatalog.PG_JDBC_EXPORTED_IMPORTED_KEYS_REPLACEMENT;
private static String replaceImportedExportedKeysQuery(
String sql, String replacedSql, String keySeq) {
int startIndex;
if (sql.contains(" AND pkn.nspname = ")) {
startIndex = sql.indexOf(" AND pkn.nspname = ");
Expand All @@ -397,9 +423,9 @@ private static String replaceImportedExportedKeysQuery(String sql) {
.replace(" AND fkc.relname = ", " AND CHILD.TABLE_NAME = ")
.replace(
" ORDER BY fkn.nspname,fkc.relname,con.conname,pos.n",
" ORDER BY CHILD.TABLE_CATALOG, CHILD.TABLE_SCHEMA, CHILD.TABLE_NAME, KEY_SEQ")
" ORDER BY CHILD.TABLE_CATALOG, CHILD.TABLE_SCHEMA, CHILD.TABLE_NAME, " + keySeq)
.replace(
" ORDER BY pkn.nspname,pkc.relname, con.conname,pos.n",
" ORDER BY PARENT.TABLE_CATALOG, PARENT.TABLE_SCHEMA, PARENT.TABLE_NAME, KEY_SEQ");
" ORDER BY PARENT.TABLE_CATALOG, PARENT.TABLE_SCHEMA, PARENT.TABLE_NAME, " + keySeq);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -71,6 +73,11 @@ public class ClientAutoDetector {
public static final String PGBENCH_USAGE_HINT =
"See https://github.com/GoogleCloudPlatform/pgadapter/blob/-/docs/pgbench.md for how to use pgbench with PGAdapter";

/** Force the detector to return this client. This should only be used for testing. */
@VisibleForTesting
public static final AtomicReference<WellKnownClient> FORCE_DETECT_CLIENT =
new AtomicReference<>();

public enum WellKnownClient {
PSQL {

Expand Down Expand Up @@ -665,6 +672,9 @@ public ImmutableMap<String, String> getDefaultParameters(Map<String, String> par
public static @Nonnull WellKnownClient detectClient(
List<String> orderParameterKeys, Map<String, String> parameters) {
for (WellKnownClient client : WellKnownClient.values()) {
if (Objects.equals(client, FORCE_DETECT_CLIENT.get())) {
return client;
}
if (client.isClient(orderParameterKeys, parameters)) {
return client;
}
Expand Down
Loading

0 comments on commit 105b220

Please sign in to comment.