From: Jeff Janes Date: Thu, 17 Jan 2019 23:41:51 +0000 (-0500) Subject: rdbms: Remove references to pg_attrdef.adsrc in Postgres code X-Git-Tag: 1.31.6~13^2 X-Git-Url: http://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=2cecc8d7be6213c7d03d072882b51680e94e06db rdbms: Remove references to pg_attrdef.adsrc in Postgres code PostgreSQL v12 will remove the long-deprecated column pg_attrdef.adsrc. The supported way to introspect into column default values is pg_get_expr(adbin, adrelid), which works back through all versions of PostgreSQL supported by wikimedia. Changing to the supported method will allow the upcoming v12 of the database to be used while maintaining compatibility with older versions, without needing to write version-specific code. This patch has been tested with maintenance/update.php and with phpunit in PostgreSQL versions 9.2, 11, and 12dev. It does not harm the first two, and fixes errors that would otherwise arise in the dev version. All unit tests which pass under version 11 now pass under 12dev as well. Bug: T237931 Change-Id: I874d347fd286b26773113d4f0c6c30d9a4055ad3 (cherry picked from commit 27d342ef4bd31da48b0e10655daf1320e3d00b50) --- diff --git a/includes/libs/rdbms/database/DatabasePostgres.php b/includes/libs/rdbms/database/DatabasePostgres.php index 94509a3c02..299eb3cd23 100644 --- a/includes/libs/rdbms/database/DatabasePostgres.php +++ b/includes/libs/rdbms/database/DatabasePostgres.php @@ -816,7 +816,7 @@ __INDEXATTR__; . ' WHERE relkind = \'r\'' . ' AND nspname = ' . $this->addQuotes( $this->getCoreSchema() ) . ' AND relname = ' . $this->addQuotes( $oldName ) - . ' AND adsrc LIKE \'nextval(%\'', + . ' AND pg_get_expr(adbin, adrelid) LIKE \'nextval(%\'', $fname ); $row = $this->fetchObject( $res ); @@ -851,10 +851,10 @@ __INDEXATTR__; } $oid = $this->fetchObject( $res )->oid; - $res = $this->query( 'SELECT adsrc FROM pg_attribute a' + $res = $this->query( 'SELECT pg_get_expr(adbin, adrelid) AS adsrc FROM pg_attribute a' . ' JOIN pg_attrdef d ON (a.attrelid=d.adrelid and a.attnum=d.adnum)' . " WHERE a.attrelid = $oid" - . ' AND adsrc LIKE \'nextval(%\'', + . ' AND pg_get_expr(adbin, adrelid) LIKE \'nextval(%\'', $fname ); $row = $this->fetchObject( $res ); diff --git a/includes/libs/rdbms/field/PostgresField.php b/includes/libs/rdbms/field/PostgresField.php index 53c3d335b1..7596a3ba0a 100644 --- a/includes/libs/rdbms/field/PostgresField.php +++ b/includes/libs/rdbms/field/PostgresField.php @@ -17,7 +17,7 @@ class PostgresField implements Field { SELECT attnotnull, attlen, conname AS conname, atthasdef, - adsrc, + pg_get_expr(adbin, adrelid) AS adsrc, COALESCE(condeferred, 'f') AS deferred, COALESCE(condeferrable, 'f') AS deferrable, CASE WHEN typname = 'int2' THEN 'smallint'