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 table_exists($table) {
35 return pg_num_rows(db_query("SELECT * FROM information_schema.tables WHERE ".
36 "table_catalog = 'iserv' AND table_name = ".qdb($table).";")) > 0;
38 function column_exists($table, $column) {
39 return table_exists($table) && pg_num_rows(db_query("SELECT * FROM ".
40 "information_schema.columns WHERE table_name = ".qdb($table)." AND ".
41 "column_name = ".qdb($column).";")) > 0;
43 function print_sql($cmd) {
48 if(isset($_SERVER["REMOTE_ADDR"])) {
49 die("Run this script as root from the command line.");
52 /*** database schema updates **************************************************/
53 echo "updating database schema... \n";
55 /** table from pre-3.0 **/
56 if(table_exists("errors") and !column_exists("errors", "pclabel")) {
57 print_sql("ALTER TABLE errors RENAME COLUMN pc_number TO pclabel;");
60 /** table from 3.0 **/
61 if(table_exists("errors") and !column_exists("errors", "pclabel")) {
62 print_sql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,".
63 "er_comment,er_commentact,er_hidden) SELECT date,name,pclabel,text,".
64 "comment,commentby,hidden FROM errors;");
65 print_sql("DROP TABLE errors;");
68 /** table from 4.0 **/
69 if(table_exists("errorreports")) {
70 print_sql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,".
71 "er_comment,er_commentact,er_hidden) SELECT er_date,er_act,er_machine,".
72 "er_text,er_comment,er_commentact,er_hidden FROM errorreports;");
73 print_sql("DROP TABLE errorreports;");
This page took 0.044483 seconds and 5 git commands to generate.