2006-09-28 18:51:52 +00:00
#! /usr/bin/env php
2004-04-18 18:40:13 +00:00
< ? php
// code for one-time database updates goes here.
// Don't run this unless you know what you're doing!
2004-04-20 05:10:40 +00:00
require_once ( " ../inc/db.inc " );
2004-04-18 18:40:13 +00:00
require_once ( " ../inc/util.inc " );
2005-03-03 19:36:32 +00:00
require_once ( " ../inc/ops.inc " );
2004-04-18 18:40:13 +00:00
2005-03-03 19:36:32 +00:00
cli_only ();
db_init_cli ();
2004-05-27 18:13:00 +00:00
2004-12-06 23:21:57 +00:00
set_time_limit ( 0 );
2005-03-02 17:57:20 +00:00
function do_query ( $query ) {
echo " Doing query: \n $query\n " ;
$result = mysql_query ( $query );
if ( ! $result ) {
2005-03-23 23:58:43 +00:00
die ( " Failed! \n " . mysql_error ());
2005-03-02 17:57:20 +00:00
} else {
echo " Success. \n " ;
}
}
2004-04-18 18:40:13 +00:00
function update_4_18_2004 () {
2005-03-02 17:57:20 +00:00
do_query ( " alter table user add cross_project_id varchar(254) not null " );
$result = do_query ( " select * from user " );
2004-04-18 18:40:13 +00:00
while ( $user = mysql_fetch_object ( $result )) {
$x = random_string ();
2005-03-02 17:57:20 +00:00
do_query ( " update user set cross_project_id=' $x ' where id= $user->id " );
2004-04-18 18:40:13 +00:00
}
}
2004-05-12 22:16:46 +00:00
function update_5_12_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-05-12 22:16:46 +00:00
" create table trickle_up (
id integer not null auto_increment ,
create_time integer not null ,
send_time integer not null ,
resultid integer not null ,
appid integer not null ,
hostid integer not null ,
handled smallint not null ,
xml text ,
primary key ( id )
) "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-05-12 22:16:46 +00:00
" create table trickle_down (
id integer not null auto_increment ,
create_time integer not null ,
resultid integer not null ,
hostid integer not null ,
handled smallint not null ,
xml text ,
primary key ( id )
) "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-05-12 22:16:46 +00:00
" alter table trickle_up add index trickle_handled (appid, handled) "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-05-12 22:16:46 +00:00
" alter table trickle_down add index trickle_host(hostid, handled) "
);
}
2004-05-27 18:13:00 +00:00
function update_5_27_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-05-27 18:13:00 +00:00
" alter table host add nresults_today integer not null "
);
}
2004-06-09 21:42:23 +00:00
function update_6_9_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-06-09 21:42:23 +00:00
" alter table profile change verification verification integer not null "
);
}
2004-06-16 19:10:24 +00:00
function update_6_15_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-06-16 19:10:24 +00:00
" alter table user add index user_name(name) "
);
}
2004-06-09 21:42:23 +00:00
2004-07-02 19:17:53 +00:00
function update_7_02_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-07-02 19:17:53 +00:00
" alter table workunit drop column result_template "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-07-02 19:17:53 +00:00
" alter table workunit add column result_template_file varchar(63) not null "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-07-02 19:17:53 +00:00
" update workunit set result_template_file='templates/foo.xml' "
);
}
2004-07-08 19:20:19 +00:00
function update_7_08_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-07-08 19:20:19 +00:00
" alter table result drop index ind_res_st "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-07-08 19:20:19 +00:00
" alter table add index ind_res_st(server_state) "
);
}
2004-09-04 23:37:49 +00:00
function update_9_04_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-09-04 23:37:49 +00:00
" insert into forum_preferences (userid, signature, posts) select user.id, user.signature, user.posts from user where user.posts > 0 or user.signature<>'' " );
}
2004-09-05 19:26:27 +00:00
function update_9_05_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-09-05 19:26:27 +00:00
" ALTER TABLE forum_preferences ADD special_user INT NOT NULL "
);
}
2004-09-27 04:26:51 +00:00
function update_9_26_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-09-27 04:26:51 +00:00
" alter table app add homogeneous_redundancy smallint not null "
);
}
2004-10-12 18:05:38 +00:00
function update_10_09_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-10-12 18:05:38 +00:00
" alter table forum_preferences add jump_to_unread tinyint(1) unsigned not null default 1 "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-10-12 18:05:38 +00:00
" alter table forum_preferences add hide_signatures tinyint(1) unsigned not null default 0 "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-10-12 18:05:38 +00:00
" alter table post add signature tinyint(1) unsigned not null default 0 "
);
}
2004-10-25 22:04:15 +00:00
function update_10_25_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-10-25 22:04:15 +00:00
" alter table forum_preferences add rated_posts varchar(254) not null "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-10-25 22:04:15 +00:00
" alter table forum_preferences add low_rating_threshold integer not null "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-10-25 22:04:15 +00:00
" alter table forum_preferences add high_rating_threshold integer not null "
);
}
2004-10-26 22:27:50 +00:00
function update_10_26_2004 () {
2005-03-02 17:57:20 +00:00
do_query ( " alter table forum_preferences modify jump_to_unread tinyint(1) unsigned not null default 0 " );
2004-10-26 22:27:50 +00:00
}
2004-12-06 22:41:19 +00:00
function update_11_24_2004 () {
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 22:41:19 +00:00
" alter table workunit change workseq_next hr_class integer not null "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 22:41:19 +00:00
" alter table workunit add priority integer not null "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 22:41:19 +00:00
" alter table workunit add mod_time timestamp "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 22:41:19 +00:00
" alter table result add priority integer not null "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 22:41:19 +00:00
" alter table result add mod_time timestamp "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 22:41:19 +00:00
" alter table host drop column projects "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 22:41:19 +00:00
" alter table host add avg_turnaround double not null "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 22:41:19 +00:00
" alter table result drop index ind_res_st "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 22:41:19 +00:00
" alter table result add index ind_res_st(server_state, priority) "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 22:41:19 +00:00
" alter table result drop index app_received_time "
);
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 22:41:19 +00:00
" alter table result add index app_mod_time(appid, mod_time desc) "
);
}
2004-12-06 23:21:57 +00:00
// or alternatively: (can run in parallel)
function update_11_24_2004_result () {
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 23:21:57 +00:00
" alter table result add priority integer not null, "
. " add mod_time timestamp, "
. " drop index ind_res_st, "
. " add index ind_res_st(server_state, priority), "
. " drop index app_received_time, "
. " add index app_mod_time(appid, mod_time desc) "
2004-12-07 11:02:46 +00:00
);
2004-12-06 23:21:57 +00:00
}
function update_11_24_2004_workunit () {
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 23:21:57 +00:00
" alter table workunit "
. " change workseq_next hr_class integer not null, "
. " add priority integer not null, "
. " add mod_time timestamp "
);
}
function update_11_24_2004_host () {
2005-03-02 17:57:20 +00:00
do_query (
2004-12-06 23:21:57 +00:00
" alter table host drop column projects, "
. " add avg_turnaround double not null "
);
}
2004-12-27 21:14:18 +00:00
function update_12_27_2004 () {
2005-03-02 17:57:20 +00:00
do_query ( " alter table workunit drop index wu_filedel " );
do_query ( " alter table workunit add index wu_filedel (file_delete_state, mod_time) " );
2004-12-27 21:14:18 +00:00
}
2005-01-07 19:45:46 +00:00
function update_1_3_2005 () {
2005-03-02 17:57:20 +00:00
do_query ( " alter table workunit drop index wu_filedel " );
do_query ( " alter table workunit add index wu_filedel (file_delete_state) " );
do_query ( " alter table result drop index app_mod_time " );
2005-01-07 19:45:46 +00:00
}
2005-01-08 19:45:26 +00:00
function update_1_7_2005 () {
2005-03-02 17:57:20 +00:00
do_query ( " alter table forum_preferences add ignorelist varchar(254) not null " );
2005-01-08 19:45:26 +00:00
}
2005-01-13 23:06:15 +00:00
function update_1_13_2005 () {
2005-03-02 17:57:20 +00:00
do_query ( " alter table thread add hidden integer not null " );
do_query ( " alter table post add hidden integer not null " );
2005-01-13 23:06:15 +00:00
}
2005-01-18 13:00:38 +00:00
function update_1_18_2005 () {
2006-08-29 20:39:44 +00:00
do_query ( " ALTER TABLE forum_preferences CHANGE special_user special_user CHAR(12) DEFAULT '0' NOT NULL " );
2005-01-18 13:00:38 +00:00
}
2005-01-19 05:44:12 +00:00
function update_1_19_2005 () {
2005-03-02 17:57:20 +00:00
do_query ( " create table tentative_user (
2005-01-19 05:44:12 +00:00
nonce varchar ( 254 ) not null ,
email_addr varchar ( 254 ) not null ,
confirmed integer not null ,
primary key ( nonce )
); "
);
}
2005-01-20 18:50:49 +00:00
function update_1_20_2005 () {
2005-03-02 17:57:20 +00:00
do_query ( " alter table host add host_cpid varchar(254) " );
2005-01-20 18:50:49 +00:00
}
2005-01-21 07:54:15 +00:00
function update_1_20a_2005 () {
2005-03-02 17:57:20 +00:00
do_query ( " alter table host add external_ip_addr varchar(254) " );
2005-01-21 07:54:15 +00:00
}
2005-02-26 00:24:37 +00:00
function update_2_25_2005 () {
2005-03-02 17:57:20 +00:00
do_query ( " alter table host add max_results_day integer not null " );
2005-04-20 21:25:18 +00:00
}
2005-02-26 00:24:37 +00:00
2005-04-20 21:25:18 +00:00
function update_4_20_2005 (){
do_query ( " ALTER TABLE `thread` ADD `sticky` TINYINT UNSIGNED DEFAULT '0' NOT NULL " );
do_query ( " ALTER TABLE `forum` ADD `post_min_total_credit` INT NOT NULL AFTER `posts` " );
do_query ( " ALTER TABLE `forum` ADD `post_min_expavg_credit` INT NOT NULL AFTER `posts` " );
do_query ( " ALTER TABLE `forum` ADD `post_min_interval` INT NOT NULL AFTER `posts` " );
do_query ( " ALTER TABLE `forum` ADD `rate_min_total_credit` INT NOT NULL AFTER `posts` " );
do_query ( " ALTER TABLE `forum` ADD `rate_min_expavg_credit` INT NOT NULL AFTER `posts` " );
do_query ( " ALTER TABLE `forum_preferences` ADD `last_post` INT( 14 ) UNSIGNED NOT NULL AFTER `posts` " );
}
2005-04-30 10:20:49 +00:00
function update_4_30_2005 (){
2005-05-04 22:38:14 +00:00
do_query ( " ALTER TABLE `forum_preferences` ADD `ignore_sticky_posts` TINYINT( 1 ) UNSIGNED NOT NULL " );
2005-04-30 10:20:49 +00:00
}
2005-06-23 07:42:45 +00:00
function update_6_22_2005 () {
do_query ( " alter table host add cpu_efficiency double not null after active_frac, add duration_correction_factor double not null after cpu_efficiency " );
}
2005-08-07 01:33:15 +00:00
function update_8_05_2005 () {
do_query ( " alter table user add passwd_hash varchar(254) not null " );
do_query ( " alter table user add email_validated smallint not null " );
do_query ( " update user set passwd_hash=MD5(concat(authenticator, email_addr)) " );
do_query ( " update user set email_validated=1 " );
}
2005-08-25 23:07:58 +00:00
function update_8_25_2005 () {
do_query ( " alter table user add donated smallint not null " );
}
2005-08-26 22:26:26 +00:00
function update_8_26_2005 () {
do_query ( " drop table tentative_user " );
}
2005-09-22 23:27:08 +00:00
function update_9_22_2005 () {
do_query ( " update user set country='Macedonia' where country='Macedonia, The Former Yugoslav Republic of' " );
}
2005-11-24 16:36:12 +00:00
function update_11_24_2005 (){
do_query ( " ALTER TABLE `forum_preferences` ADD `minimum_wrap_postcount` INT DEFAULT '100' NOT NULL AFTER `high_rating_threshold` ,
ADD `display_wrap_postcount` INT DEFAULT '75' NOT NULL AFTER `minimum_wrap_postcount` " );
}
2006-06-16 23:53:56 +00:00
function update_6_16_2006 () {
do_query ( " ALTER TABLE `thread` ADD `score` DOUBLE NOT NULL AFTER `sufferers` , ADD `votes` INT NOT NULL AFTER `score` " );
do_query ( " ALTER TABLE `forum_preferences` ADD `forum_sorting` INT NOT NULL AFTER `sorting` " );
do_query ( " ALTER TABLE `forum_preferences` ADD `thread_sorting` INT NOT NULL AFTER `forum_sorting` " );
do_query ( " CREATE TABLE `post_ratings` (
`post` INT UNSIGNED NOT NULL ,
`user` INT UNSIGNED NOT NULL ,
`rating` TINYINT NOT NULL ,
PRIMARY KEY ( `post` , `user` )) " );
do_query ( " ALTER TABLE `forum_preferences` DROP `avatar_type` " );
do_query ( " ALTER TABLE `forum_preferences` CHANGE `low_rating_threshold` `low_rating_threshold` INT( 11 ) DEFAULT '-25' NOT NULL " );
do_query ( " ALTER TABLE `forum_preferences` CHANGE `high_rating_threshold` `high_rating_threshold` INT( 11 ) DEFAULT '5' NOT NULL " );
do_query ( " ALTER TABLE `forum_preferences` CHANGE `jump_to_unread` `jump_to_unread` TINYINT( 1 ) UNSIGNED DEFAULT '1' NOT NULL " );
do_query ( " ALTER TABLE `forum_preferences` DROP `sorting` " );
do_query ( " ALTER TABLE `forum_preferences` CHANGE `no_signature_by_default` `no_signature_by_default` TINYINT( 1 ) UNSIGNED DEFAULT '1' NOT NULL " );
do_query ( " ALTER TABLE `thread` ADD `status` SMALLINT UNSIGNED NOT NULL AFTER `owner` " );
do_query ( " ALTER TABLE `subscriptions` ADD `notified` TINYINT( 1 ) UNSIGNED DEFAULT '0' NOT NULL " );
do_query ( " ALTER TABLE `subscriptions` CHANGE `notified` `notified_time` INT( 14 ) UNSIGNED DEFAULT '0' NOT NULL " );
}
2006-07-11 21:56:53 +00:00
function update_7_11_2006 () {
do_query ( " alter table app add weight double not null " );
}
2006-08-08 20:32:37 +00:00
function update_8_8_2006 () {
do_query ( " alter table forum_preferences add banished_until integer not null default 0 " );
}
2006-10-22 01:46:33 +00:00
function update_10_21_2006 () {
do_query ( " alter table app add beta smallint not null default 0 " );
}
2006-10-31 09:06:58 +00:00
function update_10_26_2006 () {
do_query ( " ALTER TABLE `team` ADD `ping_user` INT UNSIGNED NOT NULL DEFAULT '0',
ADD `ping_time` INT UNSIGNED NOT NULL DEFAULT '0' " );
do_query ( " ALTER TABLE team ADD INDEX team_userid (userid) " );
}
2006-11-10 17:09:09 +00:00
function update_11_10_2006 () {
2006-12-22 20:34:58 +00:00
do_query ( " ALTER TABLE thread ADD locked TINYINT NOT NULL DEFAULT 0 " );
2006-11-10 17:09:09 +00:00
}
2007-04-20 18:49:40 +00:00
function update_12_22_2006 () {
2007-01-22 21:49:55 +00:00
do_query ( " ALTER TABLE forum ADD is_dev_blog TINYINT NOT NULL DEFAULT 0 " );
}
2007-04-11 18:05:26 +00:00
function update_4_07_2007 () {
2007-04-12 02:57:09 +00:00
do_query ( ' create table sent_email (
2007-04-11 18:05:26 +00:00
userid integer not null ,
time_sent integer not null ,
email_type smallint not null ,
primary key ( userid )
) TYPE = MyISAM ; '
);
}
2007-01-22 21:49:55 +00:00
2007-04-24 23:21:42 +00:00
function update_4_24_2007 () {
do_query ( 'alter table host add error_rate double not null default 0' );
}
2007-04-29 14:22:28 +00:00
function update_4_29_2007 () {
do_query ( " CREATE TABLE `private_messages` (
`id` int ( 10 ) unsigned NOT NULL auto_increment ,
`userid` int ( 10 ) unsigned NOT NULL ,
`senderid` int ( 10 ) unsigned NOT NULL ,
`date` int ( 10 ) unsigned NOT NULL ,
`opened` tinyint ( 1 ) unsigned NOT NULL default '0' ,
`subject` varchar ( 255 ) NOT NULL ,
`content` text NOT NULL ,
PRIMARY KEY ( `id` ),
KEY `userid` ( `userid` )
) TYPE = MyISAM ; "
);
}
2007-05-02 18:51:51 +00:00
function update_4_30_2007 () {
2007-05-02 23:17:52 +00:00
do_query ( " create table credited_job (
2007-05-02 18:51:51 +00:00
userid integer not null ,
workunitid bigint not null
) TYPE = MyISAM ; " );
2007-05-02 23:17:52 +00:00
do_query ( " alter table credited_job add index credited_job_user (userid),
add index credited_job_wu ( workunitid ),
add unique credited_job_user_wu ( userid , workunitid ); "
2007-05-02 18:51:51 +00:00
);
}
2007-05-27 17:33:06 +00:00
function update_5_27_2007 () {
do_query ( " create table donation_items (
id integer unsigned not null auto_increment ,
item_name varchar ( 32 ) not null ,
title varchar ( 255 ) not null ,
description varchar ( 255 ) not null ,
required double unsigned not null default '0' ,
PRIMARY KEY ( id )
) TYPE = MyISAM ; " );
do_query ( " create table donation_paypal (
id integer not null auto_increment ,
order_time integer unsigned not null ,
userid integer not null ,
email_addr varchar ( 255 ) not null ,
order_amount double ( 6 , 2 ) not null ,
processed tinyint ( 1 ) not null default '0' ,
payment_time integer unsigned not null ,
item_name varchar ( 255 ) not null ,
item_number varchar ( 255 ) not null ,
payment_status varchar ( 255 ) not null ,
payment_amount double ( 6 , 2 ) not null ,
payment_fee double ( 5 , 2 ) default null ,
payment_currency varchar ( 255 ) not null ,
txn_id varchar ( 255 ) not null ,
receiver_email varchar ( 255 ) not null ,
payer_email varchar ( 255 ) not null ,
payer_name varchar ( 255 ) not null ,
PRIMARY KEY ( id )
) TYPE = MyISAM ; " );
}
2007-04-20 18:49:40 +00:00
// modify the following to call the function you want.
// Make sure you do all needed functions, in order.
// (Look at your DB structure using "explain" queries to see
// which ones you need).
2007-05-27 17:33:06 +00:00
//update_5_27_2007();
2004-04-18 18:40:13 +00:00
?>