#!/usr/bin/php 0; } function column_exists($table, $column) { return table_exists($table) && pg_num_rows(db_query("SELECT * FROM ". "information_schema.columns WHERE table_name = ".qdb($table)." AND ". "column_name = ".qdb($column).";")) > 0; } function print_sql($cmd) { echo $cmd."\n"; db_query($cmd); } if(isset($_SERVER["REMOTE_ADDR"])) { die("Run this script as root from the command line."); } /*** database schema updates **************************************************/ echo "updating database schema... \n"; /** table from pre-3.0 **/ if(table_exists("errors") and !column_exists("errors", "pclabel")) { print_sql("ALTER TABLE errors RENAME COLUMN pc_number TO pclabel;"); } /** table from 3.0 **/ if(table_exists("errors") and !column_exists("errors", "pclabel")) { print_sql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,". "er_comment,er_commentact,er_hidden) SELECT date,name,pclabel,text,". "comment,commentby,hidden FROM errors;"); print_sql("DROP TABLE errors;"); } /** table from 4.0 **/ if(table_exists("errorreports")) { print_sql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,". "er_comment,er_commentact,er_hidden) SELECT er_date,er_act,er_machine,". "er_text,er_comment,er_commentact,er_hidden FROM errorreports;"); print_sql("DROP TABLE errorreports;"); } echo "done.\n"; ?>