changeset 107:ee67bb78da2d

change: アップデート用のスクリプトを変更
author Sushi-k <epgrec@park.mda.or.jp>
date Mon, 08 Mar 2010 18:08:35 +0900
parents 57676bb30f64
children 4bd07b03c694
files upgrade_db.php
diffstat 1 files changed, 197 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/upgrade_db.php	Mon Mar 08 18:08:35 2010 +0900
@@ -0,0 +1,197 @@
+#!/usr/bin/php
+<?php
+include_once('config.php');
+include_once(INSTALL_PATH . '/Settings.class.php' );
+
+
+// mysqli::multi_query篏障<т戎
+
+function multi_query( $sqlstrs, $dbh ) {
+	$error = false;
+	
+	foreach( $sqlstrs as $sqlstr ) {
+		$res = mysql_query( $sqlstr );
+		if( $res === FALSE ) {
+			echo "failed: ". $sqlstr . "\n";
+			$error = true;
+		}
+	}
+	return $error;
+}
+
+function column_exists( $tbl, $col, $dbh ) {
+	$sqlstr = "show fields from ".$tbl." where Field='".$col."'";
+	$res = mysql_query( $sqlstr, $dbh );
+	return mysql_num_rows($res);
+}
+
+function index_exists( $tbl, $idx, $dbh ) {
+	$sqlstr = "show index from ".$tbl." where Key_name='".$idx."'";
+	$res = mysql_query( $sqlstr, $dbh );
+	return mysql_num_rows($res);
+}
+
+
+$settings = Settings::factory();
+$dbh = mysql_connect( $settings->db_host, $settings->db_user, $settings->db_pass );
+if( $dbh !== FALSE ) {
+
+	$sqlstr = "use ".$settings->db_name;
+	mysql_query( $sqlstr );
+
+	$sqlstr = "set NAMES 'utf8'";
+	mysql_query( $sqlstr );
+	
+	// RESERVE_TBL
+
+	$sqlstrs = array (
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  channel_disc varchar(128) not null default 'none';",	// channel disc
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  channel_id integer not null  default '0';",			// channel ID
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  program_id integer not null default '0';",				// Program ID
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  type varchar(8) not null default 'GR';",				// 腮ワGR/BS/CS鐚
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  channel varchar(10) not null default '0';",			// c潟
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  title varchar(512) not null default 'none';",			// 帥ゃ
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  description varchar(512) not null default 'none';",		// 茯 text->varchar
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  category_id integer not null default '0';",			// 眼ID
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  starttime datetime not null default '1970-01-01 00:00:00';",	// 紮
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  endtime datetime not null default '1970-01-01 00:00:00';",		// 腟篋
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  job integer not null default '0';",					// job
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  path blob default null;",								// 牙祉<ゃ
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  complete boolean not null default '0';",				// 絎篋
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  reserve_disc varchar(128) not null default 'none';",	// 茘ョhash
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  autorec integer not null default '0';",				// 若若ID
+	 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  mode integer not null default '0';",					//牙祉≪若
+	);
+	
+	if( multi_query( $sqlstrs, $dbh ) ) {
+		echo "篋膣若≪若紊掩\n";
+	}
+	
+	// ゃ潟壕申
+	$sqlstrs = array();
+	if( index_exists( $settings->tbl_prefix.RESERVE_TBL, "reserve_ch_idx", $dbh ) ) {
+		echo "reserve_ch_idxс絖篏障\n";
+	}
+	else {
+		array_push( $sqlstrs, "create index reserve_ch_idx on ".$settings->tbl_prefix.RESERVE_TBL."  (channel_disc);" );
+	}
+	if( index_exists( $settings->tbl_prefix.RESERVE_TBL, "reserve_st_idx", $dbh ) ) {
+		echo "reserve_st_idxс絖篏障\n";
+	}
+	else {
+		array_push( $sqlstrs, "create index reserve_st_idx on ".$settings->tbl_prefix.RESERVE_TBL."  (starttime);" );
+	}
+	if( multi_query( $sqlstrs, $dbh ) ) {
+		echo "篋膣若ゃ潟鴻篏с障\n";
+	}
+	
+	// PROGRAM_TBL
+	
+	$sqlstrs = array (
+		"alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify channel_disc varchar(128) not null default 'none';",	// channel disc
+		"alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify channel_id integer not null default '0';",				// channel ID
+		"alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify type varchar(8) not null default 'GR';",				// 腮ワGR/BS/CS鐚
+		"alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify channel varchar(10) not null default '0';",			// c潟
+		"alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify title varchar(512) not null default 'none';",			// 帥ゃ
+		"alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify description varchar(512) not null default 'none';",	// 茯 text->varchar
+		"alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify category_id integer not null default '0';",			// 眼ID
+		"alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify starttime datetime not null default '1970-01-01 00:00:00';",	// 紮
+		"alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify endtime datetime not null default '1970-01-01 00:00:00';",		// 腟篋
+		"alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify program_disc varchar(128) not null default 'none';",	 		// 茘ョhash
+		"alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify autorec boolean not null default '1';",					// 牙紙合≦
+	);
+	
+	if( multi_query( $sqlstrs, $dbh ) ) {
+		echo "腟若≪若紊掩\n";
+	}
+	
+	// ゃ潟壕申
+	$sqlstrs = array();
+	if( index_exists( $settings->tbl_prefix.PROGRAM_TBL , "program_ch_idx", $dbh ) ) {
+		echo "program_ch_idxс絖篏障\n";
+	}
+	else {
+		array_push( $sqlstrs, "create index program_ch_idx on ".$settings->tbl_prefix.PROGRAM_TBL." (channel_disc);" );
+	}
+	if( index_exists( $settings->tbl_prefix.PROGRAM_TBL , "program_st_idx", $dbh ) ) {
+		echo "program_st_idxс絖篏障\n";
+	}
+	else {
+		array_push( $sqlstrs, "create index program_st_idx on ".$settings->tbl_prefix.PROGRAM_TBL." (starttime);" );
+	}
+	if( multi_query( $sqlstrs, $dbh ) ) {
+		echo "腟若ゃ潟鴻篏с障\n";
+	}
+	
+	// CHANNEL_TBL
+	
+	$sqlstrs = array(
+		"alter table ".$settings->tbl_prefix.CHANNEL_TBL." modify type varchar(8) not null default 'GR';",				// 腮
+		"alter table ".$settings->tbl_prefix.CHANNEL_TBL." modify channel varchar(10) not null default '0';",			// channel
+		"alter table ".$settings->tbl_prefix.CHANNEL_TBL." modify name varchar(512) not null default 'none';",			// 茵腓阪
+		"alter table ".$settings->tbl_prefix.CHANNEL_TBL." modify channel_disc varchar(128) not null default 'none';",	// 茘ョhash
+	);
+	if( column_exists( $settings->tbl_prefix.CHANNEL_TBL, "sid", $dbh ) ) {
+		echo "sidc若絖т障\n";
+	}
+	else {
+		array_push( $sqlstrs , "alter table ".$settings->tbl_prefix.CHANNEL_TBL." add sid varchar(64) not null default 'hd'" );
+	}
+	if( column_exists( $settings->tbl_prefix.CHANNEL_TBL, "skip", $dbh ) ) {
+		echo "skipc若絖т障\n";
+	}
+	else {
+		array_push( $sqlstrs , "alter table ".$settings->tbl_prefix.CHANNEL_TBL." add skip boolean not null default '0'" );
+	}
+	if( multi_query( $sqlstrs, $dbh ) ) {
+		echo "c潟若≪若紊掩\n";
+	}
+	
+	// CATEGORY_TBL
+	
+	$sqlstrs  = array(
+		"alter table ".$settings->tbl_prefix.CATEGORY_TBL." modify name_jp varchar(512) not null default 'none';",		// 茵腓阪
+		"alter table ".$settings->tbl_prefix.CATEGORY_TBL." modify name_en varchar(512) not null default 'none';",		// 筝
+		"alter table ".$settings->tbl_prefix.CATEGORY_TBL." modify category_disc varchar(128) not null default 'none'",	// 茘ョhash
+	);
+	if( multi_query( $sqlstrs, $dbh ) ) {
+		echo "眼若≪若紊掩\n";
+	}
+	
+	// KEYWORD_TBL
+	
+	$sqlstrs = array(
+		"alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify keyword varchar(512) not null default '*';",			// 茵腓阪
+		"alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify type varchar(8) not null default '*';",				// 腮
+		"alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify channel_id integer not null default '0';",				// channel ID
+		"alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify category_id integer not null default '0';",			// 眼ID
+		"alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify use_regexp boolean not null default '0';",				// 罩h頫憗篏睡1
+	 );
+	if( column_exists( $settings->tbl_prefix.KEYWORD_TBL, "autorec_mode", $dbh ) ) {
+		echo "autorec_mode絖т障\n";
+	}
+	else {
+		array_push( $sqlstrs, "alter table ".$settings->tbl_prefix.KEYWORD_TBL." add autorec_mode integer not null default '0';");
+	}
+	if( column_exists( $settings->tbl_prefix.KEYWORD_TBL, "weekofday", $dbh ) ) {
+		echo "weekofday絖т障\n";
+	}
+	else {
+		array_push( $sqlstrs, "alter table ".$settings->tbl_prefix.KEYWORD_TBL." add weekofday enum ('0','1','2','3','4','5','6','7' ) default '7'" );
+	}
+	if( column_exists( $settings->tbl_prefix.KEYWORD_TBL, "prgtime", $dbh ) ) {
+		echo "prgtime絖т障\n";
+	}
+	else {
+		array_push( $sqlstrs, 
+			"alter table ".$settings->tbl_prefix.KEYWORD_TBL." add prgtime enum ('0','1','2','3','4','5','6','7','8','9','10','11','12',".
+																				"'13','14','15','16','17','18','19','20','21','22','23','24') default '24'" );
+	}
+
+	if( multi_query( $sqlstrs, $dbh ) ) {
+		echo "若若若≪若紊掩\n";
+	}
+}
+else
+	exit( "DB・膓紊掩\n" );
+?>
\ No newline at end of file