From: Sebastien D. <sde...@us...> - 2005-01-12 15:49:17
|
Update of /cvsroot/tslogparser/web/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23666/db Added Files: initial_db_schema.inc.php remove_db_data.inc.php update_db.inc.php Log Message: Include the tool on the website --- NEW FILE: initial_db_schema.inc.php --- <?php /* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. */ /* This file defines the initial database schema The output is derived from phpMyAdmin output. */ /************************************************************* *************** Initial database schema ********************* *************************************************************/ /* This creates the release 1 of the database. * On new installation, this is always the version created then * the updates are called in order up to the latest release. */ function initial_db_schema() { $queries = array(); $queries[]="CREATE TABLE `opts_domains` (" ." `dom_id` int(11) NOT NULL auto_increment," ." `dom_name` varchar(30) NOT NULL default ''," ." `dom_comment` tinytext," ." PRIMARY KEY (`dom_id`)," ." UNIQUE KEY `dom_name` (`dom_name`)" .")"; $queries[]="CREATE TABLE `opts_routines` (" ." `rou_id` int(11) NOT NULL auto_increment," ." `rou_name` varchar(50) NOT NULL default ''," ." `rou_comment` tinytext," ." PRIMARY KEY (`rou_id`)," ." UNIQUE KEY `rou_name` (`rou_name`)" .")"; $queries[]="CREATE TABLE `opts_assoc_dom_rou` (" ." `assoc_dom` int(11) NOT NULL default '0'," ." `assoc_rou` int(11) NOT NULL default '0'," ." PRIMARY KEY (`assoc_dom`,`assoc_rou`)" .")"; $queries[]="CREATE TABLE `opts_assertions` (" ." `assert_id` int(11) NOT NULL auto_increment," ." `assert_routine` int(11) NOT NULL default '0'," ." `assert_text` text," ." PRIMARY KEY (`assert_id`)" .")"; $queries[]="CREATE TABLE `opts_versions` (" ." `ver_id` int(11) NOT NULL auto_increment," ." `ver_name` varchar(50) NOT NULL default ''," ." `ver_comment` tinytext," ." `ver_module` varchar(50) NOT NULL default 'opts'," ." PRIMARY KEY (`ver_id`)," ." UNIQUE KEY `ver_name` (`ver_name`)," ." KEY `ver_name_2` (`ver_name`)" .")"; $queries[]="CREATE TABLE `opts_version_descriptions` (" ." `descr_id` int(11) NOT NULL auto_increment," ." `descr_version` int(11) NOT NULL default '0'," ." `descr_assert` int(11) NOT NULL default '0'," ." `descr_num_assert` int(11) NOT NULL default '0'," ." `descr_num_test` int(11) NOT NULL default '0'," ." `descr_info` varchar(30) default NULL," ." PRIMARY KEY (`descr_id`)" .")"; $queries[]="CREATE TABLE `opts_run` (" ." `run_id` int(11) NOT NULL auto_increment," ." `run_name` varchar(50) NOT NULL default ''," ." `run_comments` tinytext," ." PRIMARY KEY (`run_id`)," ." UNIQUE KEY `run_name` (`run_name`)" .")"; $queries[]="CREATE TABLE `opts_run_results` (" ." `res_run` int(11) NOT NULL default '0'," ." `res_testcase` int(11) NOT NULL default '0'," ." `res_status` varchar(30) NOT NULL default ''," ." `res_log` text," ." PRIMARY KEY (`res_run`,`res_testcase`)" .")"; $queries[]="CREATE TABLE `opts_config` (" ."`cfg_key` VARCHAR( 30 ) NOT NULL ," ."`cfg_val` VARCHAR( 30 ) NOT NULL ," ."PRIMARY KEY ( `cfg_key` )" .")"; $queries[]="INSERT INTO `opts_config` ( `cfg_key` , `cfg_val` )" ."VALUES (" ."'version', '1'" .")"; /* Create the tables */ foreach ($queries as $sql) { mysql_query($sql) or die("Unexpected error: ".mysql_error()); } return "<b>".count($queries)."</b> queries executed."; } ?> --- NEW FILE: update_db.inc.php --- <?php /* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. */ /* This file defines the function update_db() */ define('LATEST_VERSION', "1"); /* Example of update routine */ // function db_v1_to_v2() // { // $queries=array(); // $queries[]="ALTER TABLE opts_domain add (dom_type int, dom_owner varchar(10))"; // $queries[]="UPDATE opts_config SET cfg_val='2' WHERE cfg_key='version'"; // execute_update_queries($queries); // } function update_db( $curver = 1 ) { $tmpver = $curver; /* This is the template for future database updates */ // if ($tmpver == 1) // $tmpver = db_v1_to_v2(); // if ($tmpver == 2) // $tmpver = db_v2_to_v3(); // ... } function execute_update_queries(&$queries) { foreach ($queries as $sql) mysql_query($sql) or die("Unexpected error: ".mysql_error()); } ?> --- NEW FILE: remove_db_data.inc.php --- <?php /* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. */ /* This file defines the function remove_db_data() which will delete all the tslogparser database data. USE WITH CARE!! */ function remove_db_data() { $res=0; $tables=array( "opts_config" ,"opts_domains" ,"opts_routines" ,"opts_assoc_dom_rou" ,"opts_assertions" ,"opts_versions" ,"opts_version_descriptions" ,"opts_run" ,"opts_run_results"); foreach ($tables as $table) { $sql = "DROP TABLE ".$table; $tmp = mysql_query($sql); if ($tmp) { $res++; } } return "<b>".$res." / ".count($tables)."</b> table(s) removed."; } ?> |