Index: trunk/phase3/maintenance/postgres/archives/patch-archive2-ar_deleted.sql |
— | — | @@ -0,0 +1,18 @@ |
| 2 | +ALTER TABLE archive2 ADD ar_deleted INTEGER NOT NULL DEFAULT '0'; |
| 3 | +DROP VIEW archive; |
| 4 | + |
| 5 | +CREATE VIEW archive AS |
| 6 | +SELECT |
| 7 | + ar_namespace, ar_title, ar_text, ar_comment, ar_user, ar_user_text, |
| 8 | + ar_minor_edit, ar_flags, ar_rev_id, ar_text_id, ar_deleted, |
| 9 | + TO_CHAR(ar_timestamp, 'YYYYMMDDHH24MISS') AS ar_timestamp |
| 10 | +FROM archive2; |
| 11 | + |
| 12 | +CREATE RULE archive_insert AS ON INSERT TO archive |
| 13 | +DO INSTEAD INSERT INTO archive2 VALUES ( |
| 14 | + NEW.ar_namespace, NEW.ar_title, NEW.ar_text, NEW.ar_comment, NEW.ar_user, NEW.ar_user_text, |
| 15 | + TO_TIMESTAMP(NEW.ar_timestamp, 'YYYYMMDDHH24MISS'), |
| 16 | + NEW.ar_minor_edit, NEW.ar_flags, NEW.ar_rev_id, NEW.ar_text_id, NEW.ar_deleted |
| 17 | +); |
| 18 | + |
| 19 | + |
Index: trunk/phase3/maintenance/updaters.inc |
— | — | @@ -1168,19 +1168,23 @@ |
1169 | 1169 | return $nullable; |
1170 | 1170 | } |
1171 | 1171 | |
| 1172 | +define('PG_RELTYPE_TABLE', 'r'); |
| 1173 | +define('PG_RELTYPE_SEQUENCE', 'S'); |
| 1174 | + |
1172 | 1175 | function |
1173 | | -pg_table_exists($table) |
| 1176 | +pg_relation_exists($rel, $type) |
1174 | 1177 | { |
1175 | 1178 | global $wgDatabase, $wgDBname, $wgDBmwschema; |
1176 | 1179 | |
1177 | 1180 | $q = <<<END |
1178 | 1181 | SELECT 1 FROM pg_class, pg_namespace |
1179 | | - WHERE relnamespace=pg_namespace.oid AND relkind='r' |
| 1182 | + WHERE relnamespace=pg_namespace.oid AND relkind=%s |
1180 | 1183 | AND nspname=%s AND relname=%s |
1181 | 1184 | END; |
1182 | 1185 | $res = $wgDatabase->query(sprintf($q, |
| 1186 | + $wgDatabase->addQuotes($type), |
1183 | 1187 | $wgDatabase->addQuotes($wgDBmwschema), |
1184 | | - $wgDatabase->addQuotes($table))); |
| 1188 | + $wgDatabase->addQuotes($rel))); |
1185 | 1189 | $row = $wgDatabase->fetchRow($res); |
1186 | 1190 | $exists = !!$row; |
1187 | 1191 | $wgDatabase->freeResult($res); |
— | — | @@ -1188,6 +1192,18 @@ |
1189 | 1193 | } |
1190 | 1194 | |
1191 | 1195 | function |
| 1196 | +pg_table_exists($table) |
| 1197 | +{ |
| 1198 | + return pg_relation_exists($table, PG_RELTYPE_TABLE); |
| 1199 | +} |
| 1200 | + |
| 1201 | +function |
| 1202 | +pg_sequence_exists($seq) |
| 1203 | +{ |
| 1204 | + return pg_relation_exists($seq, PG_RELTYPE_SEQUENCE); |
| 1205 | +} |
| 1206 | + |
| 1207 | +function |
1192 | 1208 | pg_trigger_exists($table, $trigger) |
1193 | 1209 | { |
1194 | 1210 | global $wgDatabase, $wgDBname, $wgDBmwschema; |
— | — | @@ -1293,9 +1309,19 @@ |
1294 | 1310 | array("ipblocks", "ipb_anon_only", "CHAR NOT NULL DEFAULT '0'"), |
1295 | 1311 | array("ipblocks", "ipb_create_account", "CHAR NOT NULL DEFAULT '1'"), |
1296 | 1312 | array("ipblocks", "ipb_enable_autoblock", "CHAR NOT NULL DEFAULT '1'"), |
| 1313 | + array("ipblocks", "ipb_deleted", "INTEGER NOT NULL DEFAULT '0'"), |
1297 | 1314 | array("recentchanges", "rc_old_len", "INT"), |
1298 | 1315 | array("recentchanges", "rc_new_len", "INT"), |
1299 | | - array("revision", "rev_len", "INT") |
| 1316 | + array("revision", "rev_len", "INT"), |
| 1317 | + array("filearchive", "fa_deleted", "INTEGER NOT NULL DEFAULT '0'"), |
| 1318 | + array("recentchanges", "rc_deleted", "INTEGER NOT NULL DEFAULT '0'"), |
| 1319 | + array("recentchanges", "rc_logid", "INTEGER NOT NULL DEFAULT '0'"), |
| 1320 | + array("recentchanges", "rc_log_type", "TEXT"), |
| 1321 | + array("recentchanges", "rc_log_action", "TEXT"), |
| 1322 | + array("recentchanges", "rc_params", "TEXT"), |
| 1323 | + array("logging", "log_id", "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('log_log_id_seq')"), |
| 1324 | + array("logging", "log_params", "TEXT"), |
| 1325 | + array("logging", "log_deleted", "INTEGER NOT NULL DEFAULT '0'") |
1300 | 1326 | ); |
1301 | 1327 | |
1302 | 1328 | $newtables = array( |
— | — | @@ -1309,6 +1335,10 @@ |
1310 | 1336 | array("archive2", "patch-archive2.sql") |
1311 | 1337 | ); |
1312 | 1338 | |
| 1339 | + $newsequences = array( |
| 1340 | + "log_log_id_seq" |
| 1341 | + ); |
| 1342 | + |
1313 | 1343 | $newindexes = array( |
1314 | 1344 | array("revision", "rev_text_id_idx", "patch-rev_text_id_idx.sql") |
1315 | 1345 | ); |
— | — | @@ -1317,6 +1347,16 @@ |
1318 | 1348 | array("archive", "archive_delete", "patch-archive_delete.sql") |
1319 | 1349 | ); |
1320 | 1350 | |
| 1351 | + foreach ($newsequences as $ns) { |
| 1352 | + if (pg_sequence_exists($ns)) { |
| 1353 | + echo "... sequence $ns already exists\n"; |
| 1354 | + continue; |
| 1355 | + } |
| 1356 | + |
| 1357 | + echo "... create sequence $ns\n"; |
| 1358 | + $wgDatabase->query("CREATE SEQUENCE $ns"); |
| 1359 | + } |
| 1360 | + |
1321 | 1361 | foreach ($newtables as $nt) { |
1322 | 1362 | if (pg_table_exists($nt[0])) { |
1323 | 1363 | echo "... table $nt[0] already exists\n"; |
— | — | @@ -1416,6 +1456,12 @@ |
1417 | 1457 | } else |
1418 | 1458 | echo "... already have correct archive_insert rule\n"; |
1419 | 1459 | |
| 1460 | + if (!pg_column_exists("archive2", "ar_deleted")) { |
| 1461 | + echo "... add archive2.ar_deleted and recreate archive view\n"; |
| 1462 | + dbsource(archive("patch-archive2-ar_deleted.sql")); |
| 1463 | + } else |
| 1464 | + echo "... already have archive2.ar_deleted\n"; |
| 1465 | + |
1420 | 1466 | return; |
1421 | 1467 | } |
1422 | 1468 | |