Mercurial > epgrec.yaz
comparison upgrade_db.php @ 109:3450df471c8c
merged with upstream
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Tue, 09 Mar 2010 05:56:04 +0900 |
parents | ee67bb78da2d |
children | 3bed74eca373 |
comparison
equal
deleted
inserted
replaced
105:29e7a40e6587 | 109:3450df471c8c |
---|---|
1 #!/usr/bin/php | |
2 <?php | |
3 include_once('config.php'); | |
4 include_once(INSTALL_PATH . '/Settings.class.php' ); | |
5 | |
6 | |
7 // mysqli::multi_queryは動作がいまいちなので使わない | |
8 | |
9 function multi_query( $sqlstrs, $dbh ) { | |
10 $error = false; | |
11 | |
12 foreach( $sqlstrs as $sqlstr ) { | |
13 $res = mysql_query( $sqlstr ); | |
14 if( $res === FALSE ) { | |
15 echo "failed: ". $sqlstr . "\n"; | |
16 $error = true; | |
17 } | |
18 } | |
19 return $error; | |
20 } | |
21 | |
22 function column_exists( $tbl, $col, $dbh ) { | |
23 $sqlstr = "show fields from ".$tbl." where Field='".$col."'"; | |
24 $res = mysql_query( $sqlstr, $dbh ); | |
25 return mysql_num_rows($res); | |
26 } | |
27 | |
28 function index_exists( $tbl, $idx, $dbh ) { | |
29 $sqlstr = "show index from ".$tbl." where Key_name='".$idx."'"; | |
30 $res = mysql_query( $sqlstr, $dbh ); | |
31 return mysql_num_rows($res); | |
32 } | |
33 | |
34 | |
35 $settings = Settings::factory(); | |
36 $dbh = mysql_connect( $settings->db_host, $settings->db_user, $settings->db_pass ); | |
37 if( $dbh !== FALSE ) { | |
38 | |
39 $sqlstr = "use ".$settings->db_name; | |
40 mysql_query( $sqlstr ); | |
41 | |
42 $sqlstr = "set NAMES 'utf8'"; | |
43 mysql_query( $sqlstr ); | |
44 | |
45 // RESERVE_TBL | |
46 | |
47 $sqlstrs = array ( | |
48 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify channel_disc varchar(128) not null default 'none';", // channel disc | |
49 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify channel_id integer not null default '0';", // channel ID | |
50 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify program_id integer not null default '0';", // Program ID | |
51 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify type varchar(8) not null default 'GR';", // 種別(GR/BS/CS) | |
52 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify channel varchar(10) not null default '0';", // チャンネル | |
53 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify title varchar(512) not null default 'none';", // タイトル | |
54 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify description varchar(512) not null default 'none';", // 説明 text->varchar | |
55 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify category_id integer not null default '0';", // カテゴリID | |
56 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify starttime datetime not null default '1970-01-01 00:00:00';", // 開始時刻 | |
57 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify endtime datetime not null default '1970-01-01 00:00:00';", // 終了時刻 | |
58 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify job integer not null default '0';", // job番号 | |
59 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify path blob default null;", // 録画ファイルパス | |
60 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify complete boolean not null default '0';", // 完了フラグ | |
61 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify reserve_disc varchar(128) not null default 'none';", // 識別用hash | |
62 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify autorec integer not null default '0';", // キーワードID | |
63 "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify mode integer not null default '0';", //録画モード | |
64 ); | |
65 | |
66 if( multi_query( $sqlstrs, $dbh ) ) { | |
67 echo "予約テーブルのアップデートに失敗\n"; | |
68 } | |
69 | |
70 // インデックス追加 | |
71 $sqlstrs = array(); | |
72 if( index_exists( $settings->tbl_prefix.RESERVE_TBL, "reserve_ch_idx", $dbh ) ) { | |
73 echo "reserve_ch_idxはすでに存在しているため作成しません\n"; | |
74 } | |
75 else { | |
76 array_push( $sqlstrs, "create index reserve_ch_idx on ".$settings->tbl_prefix.RESERVE_TBL." (channel_disc);" ); | |
77 } | |
78 if( index_exists( $settings->tbl_prefix.RESERVE_TBL, "reserve_st_idx", $dbh ) ) { | |
79 echo "reserve_st_idxはすでに存在しているため作成しません\n"; | |
80 } | |
81 else { | |
82 array_push( $sqlstrs, "create index reserve_st_idx on ".$settings->tbl_prefix.RESERVE_TBL." (starttime);" ); | |
83 } | |
84 if( multi_query( $sqlstrs, $dbh ) ) { | |
85 echo "予約テーブルにインデックスが作成できません\n"; | |
86 } | |
87 | |
88 // PROGRAM_TBL | |
89 | |
90 $sqlstrs = array ( | |
91 "alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify channel_disc varchar(128) not null default 'none';", // channel disc | |
92 "alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify channel_id integer not null default '0';", // channel ID | |
93 "alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify type varchar(8) not null default 'GR';", // 種別(GR/BS/CS) | |
94 "alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify channel varchar(10) not null default '0';", // チャンネル | |
95 "alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify title varchar(512) not null default 'none';", // タイトル | |
96 "alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify description varchar(512) not null default 'none';", // 説明 text->varchar | |
97 "alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify category_id integer not null default '0';", // カテゴリID | |
98 "alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify starttime datetime not null default '1970-01-01 00:00:00';", // 開始時刻 | |
99 "alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify endtime datetime not null default '1970-01-01 00:00:00';", // 終了時刻 | |
100 "alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify program_disc varchar(128) not null default 'none';", // 識別用hash | |
101 "alter table ".$settings->tbl_prefix.PROGRAM_TBL." modify autorec boolean not null default '1';", // 自動録画有効無効 | |
102 ); | |
103 | |
104 if( multi_query( $sqlstrs, $dbh ) ) { | |
105 echo "番組テーブルのアップデートに失敗\n"; | |
106 } | |
107 | |
108 // インデックス追加 | |
109 $sqlstrs = array(); | |
110 if( index_exists( $settings->tbl_prefix.PROGRAM_TBL , "program_ch_idx", $dbh ) ) { | |
111 echo "program_ch_idxはすでに存在しているため作成しません\n"; | |
112 } | |
113 else { | |
114 array_push( $sqlstrs, "create index program_ch_idx on ".$settings->tbl_prefix.PROGRAM_TBL." (channel_disc);" ); | |
115 } | |
116 if( index_exists( $settings->tbl_prefix.PROGRAM_TBL , "program_st_idx", $dbh ) ) { | |
117 echo "program_st_idxはすでに存在しているため作成しません\n"; | |
118 } | |
119 else { | |
120 array_push( $sqlstrs, "create index program_st_idx on ".$settings->tbl_prefix.PROGRAM_TBL." (starttime);" ); | |
121 } | |
122 if( multi_query( $sqlstrs, $dbh ) ) { | |
123 echo "番組テーブルにインデックスが作成できません\n"; | |
124 } | |
125 | |
126 // CHANNEL_TBL | |
127 | |
128 $sqlstrs = array( | |
129 "alter table ".$settings->tbl_prefix.CHANNEL_TBL." modify type varchar(8) not null default 'GR';", // 種別 | |
130 "alter table ".$settings->tbl_prefix.CHANNEL_TBL." modify channel varchar(10) not null default '0';", // channel | |
131 "alter table ".$settings->tbl_prefix.CHANNEL_TBL." modify name varchar(512) not null default 'none';", // 表示名 | |
132 "alter table ".$settings->tbl_prefix.CHANNEL_TBL." modify channel_disc varchar(128) not null default 'none';", // 識別用hash | |
133 ); | |
134 if( column_exists( $settings->tbl_prefix.CHANNEL_TBL, "sid", $dbh ) ) { | |
135 echo "sidフィールドは存在しているので作成しません\n"; | |
136 } | |
137 else { | |
138 array_push( $sqlstrs , "alter table ".$settings->tbl_prefix.CHANNEL_TBL." add sid varchar(64) not null default 'hd'" ); | |
139 } | |
140 if( column_exists( $settings->tbl_prefix.CHANNEL_TBL, "skip", $dbh ) ) { | |
141 echo "skipフィールドは存在しているので作成しません\n"; | |
142 } | |
143 else { | |
144 array_push( $sqlstrs , "alter table ".$settings->tbl_prefix.CHANNEL_TBL." add skip boolean not null default '0'" ); | |
145 } | |
146 if( multi_query( $sqlstrs, $dbh ) ) { | |
147 echo "チャンネルテーブルのアップデートに失敗\n"; | |
148 } | |
149 | |
150 // CATEGORY_TBL | |
151 | |
152 $sqlstrs = array( | |
153 "alter table ".$settings->tbl_prefix.CATEGORY_TBL." modify name_jp varchar(512) not null default 'none';", // 表示名 | |
154 "alter table ".$settings->tbl_prefix.CATEGORY_TBL." modify name_en varchar(512) not null default 'none';", // 同上 | |
155 "alter table ".$settings->tbl_prefix.CATEGORY_TBL." modify category_disc varchar(128) not null default 'none'", // 識別用hash | |
156 ); | |
157 if( multi_query( $sqlstrs, $dbh ) ) { | |
158 echo "カテゴリテーブルのアップデートに失敗\n"; | |
159 } | |
160 | |
161 // KEYWORD_TBL | |
162 | |
163 $sqlstrs = array( | |
164 "alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify keyword varchar(512) not null default '*';", // 表示名 | |
165 "alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify type varchar(8) not null default '*';", // 種別 | |
166 "alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify channel_id integer not null default '0';", // channel ID | |
167 "alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify category_id integer not null default '0';", // カテゴリID | |
168 "alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify use_regexp boolean not null default '0';", // 正規表現を使用するなら1 | |
169 ); | |
170 if( column_exists( $settings->tbl_prefix.KEYWORD_TBL, "autorec_mode", $dbh ) ) { | |
171 echo "autorec_modeは存在しているので作成しません\n"; | |
172 } | |
173 else { | |
174 array_push( $sqlstrs, "alter table ".$settings->tbl_prefix.KEYWORD_TBL." add autorec_mode integer not null default '0';"); | |
175 } | |
176 if( column_exists( $settings->tbl_prefix.KEYWORD_TBL, "weekofday", $dbh ) ) { | |
177 echo "weekofdayは存在しているので作成しません\n"; | |
178 } | |
179 else { | |
180 array_push( $sqlstrs, "alter table ".$settings->tbl_prefix.KEYWORD_TBL." add weekofday enum ('0','1','2','3','4','5','6','7' ) default '7'" ); | |
181 } | |
182 if( column_exists( $settings->tbl_prefix.KEYWORD_TBL, "prgtime", $dbh ) ) { | |
183 echo "prgtimeは存在しているので作成しません\n"; | |
184 } | |
185 else { | |
186 array_push( $sqlstrs, | |
187 "alter table ".$settings->tbl_prefix.KEYWORD_TBL." add prgtime enum ('0','1','2','3','4','5','6','7','8','9','10','11','12',". | |
188 "'13','14','15','16','17','18','19','20','21','22','23','24') default '24'" ); | |
189 } | |
190 | |
191 if( multi_query( $sqlstrs, $dbh ) ) { | |
192 echo "キーワードテーブルのアップデートに失敗\n"; | |
193 } | |
194 } | |
195 else | |
196 exit( "DBの接続に失敗\n" ); | |
197 ?> |