Move db updates to 197

This commit is contained in:
dave 2010-07-13 03:30:07 +00:00
parent 801d2580be
commit 61a9d73835
2 changed files with 116 additions and 0 deletions

64
db/db.update.197.php Normal file
View File

@ -0,0 +1,64 @@
<?
function db_update_197_post()
{
echo "Migrating passwordset and oldpassword data...\n";
$q = mysql_query("SELECT * FROM accounts");
echo mysql_error();
while($a = mysql_fetch_assoc($q)) {
$aid = $a['id'];
$qq = mysql_query("SELECT * FROM users WHERE accounts_id=$aid ORDER BY year DESC LIMIT 1");
echo mysql_error();
if(mysql_num_rows($qq)) {
$u = mysql_fetch_assoc($qq);
$set = $u['passwordset'];
$old = mysql_escape_string($u['oldpassword']);
} else {
$set = '0000-00-00';
$old = '';
}
mysql_query("UPDATE accounts SET passwordset='$set',oldpassword='$old' WHERE id=$aid");
echo mysql_error();
}
echo "Migating conference ID from user_roles to users...\n";
$q = mysql_query("SELECT * FROM users");
echo mysql_error();
while($u = mysql_fetch_assoc($q)) {
$id = $u['id'];
$qq = mysql_query("SELECT * FROM user_roles WHERE users_id=$id LIMIT 1");
echo mysql_error();
if(mysql_num_rows($qq)) {
$r = mysql_fetch_assoc($qq);
mysql_query("UPDATE users SET conferences_id='{$r['conferences_id']}' WHERE id=$id");
echo mysql_error();
} else {
echo " No role data for user $id, skipping\n";
}
}
echo "Migating admin/config access to roles...\n";
$q = mysql_query("SELECT * FROM users");
echo mysql_error();
while($u = mysql_fetch_assoc($q)) {
$id = $u['id'];
$qq = mysql_query("SELECT * FROM user_roles WHERE users_id=$id AND roles_id='2'");
echo mysql_error();
if(mysql_num_rows($qq)) {
/* User has a committee role, add config/admin roles */
if($u['access_admin'] == 'yes') {
mysql_query("INSERT INTO user_roles(`accounts_id`,`users_id`,`roles_id`,`active`,`complete`)
VALUES('{$u['accounts_id']}','$id',12,'yes','yes')");
}
if($u['access_config'] == 'yes') {
mysql_query("INSERT INTO user_roles(`accounts_id`,`users_id`,`roles_id`,`active`,`complete`)
VALUES('{$u['accounts_id']}','$id',13,'yes','yes')");
}
}
}
echo "Done.\n";
}

52
db/db.update.197.sql Normal file
View File

@ -0,0 +1,52 @@
-- Rename role columns, we know they're roles, we don't need a "role" prefix
ALTER TABLE `roles` CHANGE `roletype` `type` VARCHAR( 256 ) NOT NULL;
ALTER TABLE `roles` CHANGE `rolename` `name` VARCHAR( 256 ) NOT NULL;
-- Create space for remaining password info, will be migrated in the php script, deleted in the next db update
ALTER TABLE `accounts` ADD `passwordset` DATE NOT NULL AFTER `password`;
ALTER TABLE `accounts` ADD `oldpassword` VARCHAR( 64 ) NOT NULL AFTER `passwordset`;
-- The unique ID is now the accounts_id, call it that
ALTER TABLE `users` CHANGE `uid` `accounts_id` INT( 11 ) NOT NULL ;
-- Add comments to all the new user fields so we know which role they belong to in phpmyadmin (purely cosmetic)
ALTER TABLE `users` CHANGE `fairs_id` `fairs_id` INT(11) NOT NULL COMMENT 'fair';
ALTER TABLE `users` CHANGE `years_school` `years_school` TINYINT(4) NOT NULL COMMENT 'judge';
ALTER TABLE `users` CHANGE `years_regional` `years_regional` TINYINT(4) NOT NULL COMMENT 'judge';
ALTER TABLE `users` CHANGE `years_national` `years_national` TINYINT(4) NOT NULL COMMENT 'judge';
ALTER TABLE `users` CHANGE `willing_chair` `willing_chair` ENUM('yes','no') NOT NULL DEFAULT 'no' COMMENT 'judge';
ALTER TABLE `users` CHANGE `special_award_only` `special_award_only` ENUM('yes','no') NOT NULL DEFAULT 'no' COMMENT 'judge';
ALTER TABLE `users` CHANGE `cat_prefs` `cat_prefs` TINYTEXT NULL DEFAULT NULL COMMENT 'judge';
ALTER TABLE `users` CHANGE `div_prefs` `div_prefs` TINYTEXT NULL DEFAULT NULL COMMENT 'judge';
ALTER TABLE `users` CHANGE `divsub_prefs` `divsub_prefs` TINYTEXT NULL DEFAULT NULL COMMENT 'judge';
ALTER TABLE `users` CHANGE `languages` `languages` TINYTEXT NULL DEFAULT NULL COMMENT 'judge';
ALTER TABLE `users` CHANGE `highest_psd` `highest_psd` TINYTEXT NULL DEFAULT NULL COMMENT 'judge';
ALTER TABLE `users` CHANGE `expertise_other` `expertise_other` TINYTEXT NULL DEFAULT NULL COMMENT 'judge';
ALTER TABLE `users` CHANGE `sponsors_id` `sponsors_id` INT( 11 ) NOT NULL DEFAULT '0' COMMENT 'sponsor';
ALTER TABLE `users` CHANGE `primary` `primary` ENUM( 'no', 'yes' ) NULL DEFAULT NULL COMMENT 'sponsor';
ALTER TABLE `users` CHANGE `position` `position` VARCHAR( 64 ) NULL DEFAULT NULL COMMENT 'sponsor';
ALTER TABLE `users` CHANGE `notes` `notes` TEXT NULL DEFAULT NULL COMMENT 'sponsor';
ALTER TABLE `users` CHANGE `schools_id` `schools_id` INT( 11 ) NOT NULL COMMENT 'student';
ALTER TABLE `users` CHANGE `grade` `grade` INT( 11 ) NULL DEFAULT NULL COMMENT 'student';
-- Remove unneeded table, this linkage is in user_roles
DROP TABLE `users_conferences_link`;
-- Add conferences ID to users
ALTER TABLE `users` ADD `conferences_id` INT NOT NULL AFTER `accounts_id`;
-- Change the (unique) index in the users table from (username,year)
-- to (accounts_id,conferences_id)
ALTER TABLE `users` DROP INDEX `username`;
ALTER TABLE `users` ADD UNIQUE (`accounts_id` , `conferences_id`);
-- Add deleted/deleted_datetime data to the accounts table
ALTER TABLE `accounts` ADD `deleted` ENUM( 'no', 'yes' ) NOT NULL DEFAULT 'no' AFTER `superuser`;
ALTER TABLE `accounts` ADD `deleted_datetime` DATETIME NOT NULL AFTER `deleted`;
UPDATE `accounts` SET `deleted`='no';
-- Separate committee access levels into roles
INSERT INTO `roles` (`id` ,`type` ,`name`) VALUES
(12 , 'admin', 'Fair Administrator'),
(13 , 'config', 'Fair Configurator');