Index: trunk/phase3/maintenance/postgres/tables.sql |
— | — | @@ -259,7 +259,7 @@ |
260 | 260 | CREATE INDEX img_sha1 ON image (img_sha1); |
261 | 261 | |
262 | 262 | CREATE TABLE oldimage ( |
263 | | - oi_name TEXT NOT NULL REFERENCES image(img_name), |
| 263 | + oi_name TEXT NOT NULL, |
264 | 264 | oi_archive_name TEXT NOT NULL, |
265 | 265 | oi_size INTEGER NOT NULL, |
266 | 266 | oi_width INTEGER NOT NULL, |
— | — | @@ -276,6 +276,7 @@ |
277 | 277 | oi_deleted CHAR NOT NULL DEFAULT '0', |
278 | 278 | oi_sha1 TEXT NOT NULL DEFAULT '' |
279 | 279 | ); |
| 280 | +ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascade FOREIGN KEY (oi_name) REFERENCES image(img_name) ON DELETE CASCADE; |
280 | 281 | CREATE INDEX oi_name_timestamp ON oldimage (oi_name,oi_timestamp); |
281 | 282 | CREATE INDEX oi_name_archive_name ON oldimage (oi_name,oi_archive_name); |
282 | 283 | CREATE INDEX oi_sha1 ON oldimage (oi_sha1); |
— | — | @@ -286,7 +287,7 @@ |
287 | 288 | fa_name TEXT NOT NULL, |
288 | 289 | fa_archive_name TEXT, |
289 | 290 | fa_storage_group VARCHAR(16), |
290 | | - fa_storage_key CHAR(64), |
| 291 | + fa_storage_key TEXT, |
291 | 292 | fa_deleted_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL, |
292 | 293 | fa_deleted_timestamp TIMESTAMPTZ NOT NULL, |
293 | 294 | fa_deleted_reason TEXT, |
Index: trunk/phase3/maintenance/updaters.inc |
— | — | @@ -1352,6 +1352,7 @@ |
1353 | 1353 | # table, column, desired type, USING clause if needed |
1354 | 1354 | $typechanges = array( |
1355 | 1355 | array("filearchive", "fa_metadata", "bytea", "decode(fa_metadata,'escape')"), |
| 1356 | + array("filearchive", "fa_storage_key", "text", ""), |
1356 | 1357 | array("image", "img_metadata", "bytea", "decode(img_metadata,'escape')"), |
1357 | 1358 | array("image", "img_size", "int4", ""), |
1358 | 1359 | array("image", "img_width", "int4", ""), |
— | — | @@ -1459,6 +1460,13 @@ |
1460 | 1461 | dbsource(archive($nr[2])); |
1461 | 1462 | } |
1462 | 1463 | |
| 1464 | + if ($wgDatabase->hasConstraint("oldimage_oi_name_fkey")) { |
| 1465 | + echo "... change oldimage to CASCADE DELETE on image deletion\n"; |
| 1466 | + $wgDatabase->query("ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey"); |
| 1467 | + $wgDatabase->query("ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascade ". |
| 1468 | + "FOREIGN KEY (oi_name) REFERENCES image(img_name) ON DELETE CASCADE"); |
| 1469 | + } |
| 1470 | + |
1463 | 1471 | if (!$wgDatabase->triggerExists("page", "page_deleted")) { |
1464 | 1472 | echo "... create page_deleted trigger\n"; |
1465 | 1473 | dbsource(archive('patch-page_deleted.sql')); |
Index: trunk/phase3/includes/filerepo/LocalFile.php |
— | — | @@ -1188,12 +1188,12 @@ |
1189 | 1189 | list( $oldRels, $deleteCurrent ) = $this->getOldRels(); |
1190 | 1190 | |
1191 | 1191 | if ( $deleteCurrent ) { |
| 1192 | + $concat = $dbw->buildConcat( array( "img_sha1", $encExt ) ); |
1192 | 1193 | $where = array( 'img_name' => $this->file->getName() ); |
1193 | 1194 | $dbw->insertSelect( 'filearchive', 'image', |
1194 | 1195 | array( |
1195 | 1196 | 'fa_storage_group' => $encGroup, |
1196 | | - 'fa_storage_key' => "IF(img_sha1='', '', CONCAT(img_sha1,$encExt))", |
1197 | | - |
| 1197 | + 'fa_storage_key' => "CASE WHEN img_sha1='' THEN '' ELSE $concat END", |
1198 | 1198 | 'fa_deleted_user' => $encUserId, |
1199 | 1199 | 'fa_deleted_timestamp' => $encTimestamp, |
1200 | 1200 | 'fa_deleted_reason' => $encReason, |
— | — | @@ -1217,15 +1217,14 @@ |
1218 | 1218 | } |
1219 | 1219 | |
1220 | 1220 | if ( count( $oldRels ) ) { |
| 1221 | + $concat = $dbw->buildConcat( array( "oi_sha1", $encExt ) ); |
1221 | 1222 | $where = array( |
1222 | 1223 | 'oi_name' => $this->file->getName(), |
1223 | 1224 | 'oi_archive_name IN (' . $dbw->makeList( array_keys( $oldRels ) ) . ')' ); |
1224 | | - |
1225 | 1225 | $dbw->insertSelect( 'filearchive', 'oldimage', |
1226 | 1226 | array( |
1227 | 1227 | 'fa_storage_group' => $encGroup, |
1228 | | - 'fa_storage_key' => "IF(oi_sha1='', '', CONCAT(oi_sha1,$encExt))", |
1229 | | - |
| 1228 | + 'fa_storage_key' => "CASE WHEN oi_sha1='' THEN '' ELSE $concat END", |
1230 | 1229 | 'fa_deleted_user' => $encUserId, |
1231 | 1230 | 'fa_deleted_timestamp' => $encTimestamp, |
1232 | 1231 | 'fa_deleted_reason' => $encReason, |
Index: trunk/phase3/includes/DatabasePostgres.php |
— | — | @@ -112,6 +112,11 @@ |
113 | 113 | return true; |
114 | 114 | } |
115 | 115 | |
| 116 | + function hasConstraint( $name ) { |
| 117 | + $SQL = "SELECT 1 FROM pg_catalog.pg_constraint WHERE conname = '" . pg_escape_string( $name ) . "'"; |
| 118 | + return $this->numRows($res = $this->doQuery($SQL)); |
| 119 | + } |
| 120 | + |
116 | 121 | static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0) |
117 | 122 | { |
118 | 123 | return new DatabasePostgres( $server, $user, $password, $dbName, $failFunction, $flags ); |
— | — | @@ -1235,6 +1240,10 @@ |
1236 | 1241 | return false; |
1237 | 1242 | } |
1238 | 1243 | |
| 1244 | + function buildConcat( $stringList ) { |
| 1245 | + return implode( ' || ', $stringList ); |
| 1246 | + } |
| 1247 | + |
1239 | 1248 | } // end DatabasePostgres class |
1240 | 1249 | |
1241 | 1250 | |
Index: trunk/phase3/includes/Database.php |
— | — | @@ -2302,6 +2302,13 @@ |
2303 | 2303 | return $this->tableName( $matches[1] ); |
2304 | 2304 | } |
2305 | 2305 | |
| 2306 | + /* |
| 2307 | + * Build a concatenation list to feed into a SQL query |
| 2308 | + */ |
| 2309 | + function buildConcat( $stringList ) { |
| 2310 | + return 'CONCAT(' . implode( ',', $stringList ) . ')'; |
| 2311 | + } |
| 2312 | + |
2306 | 2313 | } |
2307 | 2314 | |
2308 | 2315 | /** |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -63,6 +63,8 @@ |
64 | 64 | when boolean settings are disabled with 'Off' via php_admin_value/php_value |
65 | 65 | * (bug 11292) Fixed unserialize errors with Postgres by creating special Blob object. |
66 | 66 | * (bug 11363) Make all metadata fields bytea when using Postgres. |
| 67 | +* (bug 11331) Add buildConcat() and use CASE not IF for DB compatibility. Make oldimage |
| 68 | + cascade delete via image table for Postgres, change fa_storage_key TEXT. |
67 | 69 | |
68 | 70 | === API changes in 1.12 === |
69 | 71 | |