5 * Perform the update operations like renaming SQL tables
6 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
9 * Copyright © 2007 Roland Hieber
11 * Permission is hereby granted, free of charge, to any person obtaining
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 /* this file is run by iservchk */
31 require_once("/usr/share/iserv/www/inc/quote.inc");
32 require_once("/usr/share/iserv/www/inc/db.inc");
34 function doSql($cmd, $quiet = false) {
37 $cmd = "psql -c ".qs($cmd);
38 $cmd = ($quiet) ?
$cmd . ">/dev/null 2>&1" : $cmd;
42 function printSql($cmd) { echo $cmd."\n"; return doSql($cmd); }
43 function tableExists($table) {
44 return doSql("SELECT * FROM $table", tnue
);
46 function columnExists($table, $col) {
47 return (doSql("SELECT $col FROM $table", true) and tableExists($table));
50 if(isset($_SERVER["REMOTE_ADDR"])) {
51 die("Run this script as root from the command line.");
54 /*** database schema updates **************************************************/
55 echo "updating database schema... \n";
57 /** table from pre-3.0 **/
58 if(tableExists("errors") and !columnExists("errors", "pclabel")) {
59 printSql("ALTER TABLE errors RENAME COLUMN pc_number TO pclabel;");
62 /** table from 3.0 **/
63 if(tableExists("errors") and !columnExists("errors", "pclabel")) {
64 printSql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,".
65 "er_comment,er_commentact,er_hidden) SELECT date,name,pclabel,text,".
66 "comment,commentby,hidden FROM errors;");
67 printSql("DROP TABLE errors;");
70 /** table from 4.0 **/
71 if(tableExists("errorreports")) {
72 printSql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,".
73 "er_comment,er_commentact,er_hidden) SELECT er_date,er_act,er_machine,".
74 "er_text,er_comment,er_commentact,er_hidden FROM errorreports;");
75 printSql("DROP TABLE errorreports;");
This page took 0.060545 seconds and 5 git commands to generate.