From fa699166070a22e2967e216b43af277335249b55 Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 15 Jul 2010 21:18:36 +0000 Subject: [PATCH] Adding conferences_id fields to judges tables. Will later drop the year fields --- db/db.code.version.txt | 2 +- db/db.update.204.php | 46 ++++++++++++++++++++++++++++++++++++++++++ db/db.update.204.sql | 7 +++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100755 db/db.update.204.php create mode 100644 db/db.update.204.sql diff --git a/db/db.code.version.txt b/db/db.code.version.txt index bb2ee19..ad03f7c 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -203 +204 diff --git a/db/db.update.204.php b/db/db.update.204.php new file mode 100755 index 0000000..16e0ed9 --- /dev/null +++ b/db/db.update.204.php @@ -0,0 +1,46 @@ + conference_id links + $q1 = mysql_query("SELECT year, id FROM conferences"); + while($r = mysql_fetch_assoc($q1)){ + + foreach($tables as $tableName){ + $query = "UPDATE `$tableName` SET `conferences_id` = {$r['id']} WHERE `year` = {$r['year']}"; + mysql_query($query); + echo $query . ";\n"; + } + } + + // a couple more + foreach($tables as $tableName){ + $query = "UPDATE `$tableName` SET `conferences_id` = -1 WHERE `year` = -1"; + mysql_query($query); + echo $query . ";\n"; + + $query = mysql_query("SELECT DISTINCT(year) FROM `$tableName` WHERE `conferences_id` = 0"); + $badYears = array(); + while($data = mysql_fetch_assoc($query)){ + $badYears[] = $data['year']; + } + if(count($badYears) > 0){ + echo "ERROR: could not update conference_id in the table '$tableName' for the years "; + echo implode(', ', $badYears) . "\n"; + } + } +} +?> diff --git a/db/db.update.204.sql b/db/db.update.204.sql new file mode 100644 index 0000000..815a979 --- /dev/null +++ b/db/db.update.204.sql @@ -0,0 +1,7 @@ +ALTER TABLE `judges_schedulerconfig` ADD `conferences_id` INT NOT NULL; +ALTER TABLE `judges_teams` ADD `conferences_id` INT NOT NULL; +ALTER TABLE `judges_teams_awards_link` ADD `conferences_id` INT NOT NULL; +ALTER TABLE `judges_teams_link` ADD `conferences_id` INT NOT NULL; +ALTER TABLE `judges_teams_timeslots_link` ADD `conferences_id` INT NOT NULL; +ALTER TABLE `judges_teams_timeslots_projects_link` ADD `conferences_id` INT NOT NULL; +ALTER TABLE `judges_timeslots` ADD `conferences_id` INT NOT NULL;