function updateSchema($conf) { global $OK; // avoid error message about timezone, set to $Opt // (which might be overridden by database values later) if (function_exists("date_default_timezone_set") && $conf->opt("timezone")) { date_default_timezone_set($conf->opt("timezone")); } while (($result = $conf->ql("insert into Settings set name='__schema_lock', value=1 on duplicate key update value=1")) && $result->affected_rows == 0) { time_nanosleep(0, 200000000); } $conf->update_schema_version(null); error_log($conf->dbname . ": updating schema from version " . $conf->sversion); if ($conf->sversion == 58 && $conf->ql("alter table ContactInfo add `college` tinyint(1) NOT NULL DEFAULT '0'") && $conf->ql("alter table ContactInfo add `extension` tinyint(1) NOT NULL DEFAULT '0'")) { $conf->update_schema_version(59); } if ($conf->sversion == 59 && $conf->ql("alter table Repository add `lastpset` int(11) NOT NULL DEFAULT '0'") && $conf->ql("update Repository join ContactLink on (ContactLink.type=" . LINK_REPO . " and ContactLink.link=Repository.repoid) set Repository.lastpset=greatest(Repository.lastpset,ContactLink.pset)")) { $conf->update_schema_version(60); } if ($conf->sversion == 60 && $conf->ql("alter table Repository add `working` int(1) NOT NULL DEFAULT '1'")) { $conf->update_schema_version(61); } if ($conf->sversion == 61 && $conf->ql("alter table ContactInfo add `dropped` tinyint(1) NOT NULL DEFAULT '0'")) { $conf->update_schema_version(62); } if ($conf->sversion == 62 && $conf->ql("alter table ContactInfo drop column `dropped`") && $conf->ql("alter table ContactInfo add `dropped` int(11) NOT NULL DEFAULT '0'")) { $conf->update_schema_version(63); } if ($conf->sversion == 63 && $conf->ql("alter table Repository add `snapcommitat` int(11) NOT NULL DEFAULT '0'") && $conf->ql("alter table Repository add `snapcommitline` varchar(100)")) { $conf->update_schema_version(64); } if ($conf->sversion == 64 && $conf->ql("drop table if exists `CommitNotes`") && $conf->ql("alter table `Repository` modify `snaphash` binary(40)") && $conf->ql("create table `CommitNotes` ( `hash` binary(40) NOT NULL, `notes` BLOB NOT NULL, UNIQUE KEY `hash` (`hash`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8")) { $conf->update_schema_version(65); } if ($conf->sversion == 65 && $conf->ql("drop table if exists `RepositoryGrade`") && $conf->ql("create table `RepositoryGrade` ( `repoid` int(11) NOT NULL, `pset` int(11) NOT NULL, `gradehash` binary(40), `gradercid` int(11), UNIQUE KEY `repopset` (`repoid`,`pset`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8")) { $conf->update_schema_version(66); } if ($conf->sversion == 66 && $conf->ql("alter table RepositoryGrade add `hidegrade` tinyint(1) NOT NULL DEFAULT '0'")) { $conf->update_schema_version(67); } if ($conf->sversion == 67 && $conf->ql("drop table if exists `ExecutionQueue`") && $conf->ql("create table `ExecutionQueue` ( `queueid` int(11) NOT NULL AUTO_INCREMENT, `queueclass` varchar(20) NOT NULL, `repoid` int(11) NOT NULL, `insertat` int(11) NOT NULL, `updateat` int(11) NOT NULL, `runat` int(11) NOT NULL, `status` int(1) NOT NULL, `lockfile` varchar(1024), PRIMARY KEY (`queueid`), KEY `queueclass` (`queueclass`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8")) { $conf->update_schema_version(68); } if ($conf->sversion == 68 && $conf->ql("alter table Repository add `notes` VARBINARY(32767)") && $conf->ql("alter table CommitNotes modify `notes` VARBINARY(32767)")) { $conf->update_schema_version(69); } if ($conf->sversion == 69 && $conf->ql("alter table CommitNotes add `haslinenotes` tinyint(1) NOT NULL DEFAULT '0'") && $conf->ql("update CommitNotes set haslinenotes=1 where notes like '%\"linenotes\":{\"%'")) { $conf->update_schema_version(70); } if ($conf->sversion == 70 && $conf->ql("alter table ExecutionQueue add `nconcurrent` int(11)")) { $conf->update_schema_version(71); } if ($conf->sversion == 71 && _update_schema_haslinenotes($conf)) { $conf->update_schema_version(72); } if ($conf->sversion == 72 && _update_schema_pset_commitnotes($conf)) { $conf->update_schema_version(73); } if ($conf->sversion == 73 && $conf->ql("drop table if exists `ContactGrade`") && $conf->ql("create table `ContactGrade` ( `cid` int(11) NOT NULL, `pset` int(11) NOT NULL, `gradercid` int(11), `notes` varbinary(32767), UNIQUE KEY `cidpset` (`cid`,`pset`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8")) { $conf->update_schema_version(74); } if ($conf->sversion == 74 && $conf->ql("alter table ContactGrade add `hidegrade` tinyint(1) NOT NULL DEFAULT '0'")) { $conf->update_schema_version(75); } if ($conf->sversion == 75 && $conf->ql("alter table Settings modify `data` varbinary(32767) DEFAULT NULL")) { $conf->update_schema_version(76); } if ($conf->sversion == 76 && $conf->ql("alter table Repository add `otherheads` varbinary(8192) DEFAULT NULL")) { $conf->update_schema_version(77); } if ($conf->sversion == 77 && $conf->ql("alter table Repository change `otherheads` `heads` varbinary(8192) DEFAULT NULL")) { $conf->update_schema_version(78); } if ($conf->sversion == 78 && $conf->ql("alter table CommitNotes add `repoid` int(11) NOT NULL DEFAULT '0'") && $conf->ql("alter table CommitNotes add `nrepo` int(11) NOT NULL DEFAULT '0'")) { $conf->update_schema_version(79); } if ($conf->sversion == 79 && $conf->ql("alter table ContactInfo add `passwordTime` int(11) NOT NULL DEFAULT '0'")) { $conf->update_schema_version(80); } if ($conf->sversion == 80 && $conf->ql("alter table ExecutionQueue add `autorun` tinyint(1) NOT NULL DEFAULT '0'")) { $conf->update_schema_version(81); } if ($conf->sversion == 81 && $conf->ql("alter table ExecutionQueue add `psetid` int(11)") && $conf->ql("alter table ExecutionQueue add `runnername` varbinary(128)")) { $conf->update_schema_version(82); } if ($conf->sversion == 82 && $conf->ql("alter table ExecutionQueue add `hash` binary(40)")) { $conf->update_schema_version(83); } if ($conf->sversion == 83 && $conf->ql("create table `RepositoryGradeRequest` ( `repoid` int(11) NOT NULL, `pset` int(11) NOT NULL, `hash` binary(40) DEFAULT NULL, `requested_at` int(11) NOT NULL, UNIQUE KEY `repopsethash` (`repoid`,`pset`,`hash`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8")) { $conf->update_schema_version(84); } if ($conf->sversion == 84 && $conf->ql("drop table if exists Partner")) { $conf->update_schema_version(85); } if ($conf->sversion == 85 && $conf->ql("drop table if exists Chair") && $conf->ql("drop table if exists ChairAssistant") && $conf->ql("drop table if exists PCMember")) { $conf->update_schema_version(86); } if ($conf->sversion == 86 && $conf->ql("alter table RepositoryGrade add `placeholder` tinyint(1) NOT NULL DEFAULT '0'") && $conf->ql("alter table RepositoryGrade add `placeholder_at` int(11) DEFAULT NULL")) { $conf->update_schema_version(87); } if ($conf->sversion == 87 && $conf->ql("alter table `ContactInfo` add `anon_username` varbinary(40) DEFAULT NULL") && $conf->ql("alter table `ContactInfo` add unique key `anon_username` (`anon_username`)")) { $conf->update_schema_version(88); } if ($conf->sversion == 88 && $conf->ql("create table `ContactImage` ( `contactImageId` int(11) NOT NULL AUTO_INCREMENT, `contactId` int(11) NOT NULL, `mimetype` varbinary(128) DEFAULT NULL, `data` varbinary(32768) DEFAULT NULL, PRIMARY KEY (`contactImageId`), KEY `contactId` (`contactId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8") && $conf->ql("alter table `ContactInfo` add `contactImageId` int(11) DEFAULT NULL")) { $conf->update_schema_version(89); } if ($conf->sversion == 89 && $conf->ql("alter table ContactImage change `data` `data` mediumblob DEFAULT NULL")) { $conf->update_schema_version(90); } if ($conf->sversion == 90 && $conf->ql("alter table ExecutionQueue add `inputfifo` varchar(1024) DEFAULT NULL")) { $conf->update_schema_version(91); } if ($conf->sversion == 91 && update_schema_drop_keys_if_exist($conf, "CommitNotes", ["hashpset", "PRIMARY"]) && $conf->ql("alter table CommitNotes add primary key (`hash`,`pset`)") && update_schema_drop_keys_if_exist($conf, "ContactGrade", ["cidpset", "PRIMARY"]) && $conf->ql("alter table ContactGrade add primary key (`cid`,`pset`)") && $conf->ql("alter table ActionLog ENGINE=InnoDB") && $conf->ql("alter table Capability ENGINE=InnoDB") && $conf->ql("alter table CapabilityMap ENGINE=InnoDB") && $conf->ql("alter table CommitNotes ENGINE=InnoDB") && $conf->ql("alter table ContactGrade ENGINE=InnoDB") && update_schema_drop_keys_if_exist($conf, "ContactInfo", ["name", "affiliation", "email_3", "firstName_2", "lastName"]) && $conf->ql("alter table ContactInfo ENGINE=InnoDB") && $conf->ql("alter table ContactLink ENGINE=InnoDB") && $conf->ql("alter table ExecutionQueue ENGINE=InnoDB") && $conf->ql("alter table Formula ENGINE=InnoDB") && $conf->ql("alter table MailLog ENGINE=InnoDB") && $conf->ql("alter table OptionType ENGINE=InnoDB") && $conf->ql("alter table PaperConflict ENGINE=InnoDB") && $conf->ql("alter table PaperStorage ENGINE=InnoDB") && $conf->ql("alter table PsetGrade ENGINE=InnoDB") && $conf->ql("alter table Repository ENGINE=InnoDB") && $conf->ql("alter table RepositoryGrade ENGINE=InnoDB") && $conf->ql("alter table RepositoryGradeRequest ENGINE=InnoDB") && $conf->ql("alter table Settings ENGINE=InnoDB")) { $conf->update_schema_version(92); } if ($conf->sversion == 92 && $conf->ql("alter table ContactInfo add `github_username` varbinary(120) DEFAULT NULL")) { $conf->update_schema_version(93); } if ($conf->sversion == 93 && $conf->ql("alter table ContactInfo add `passwordUseTime` int(11) NOT NULL DEFAULT '0'") && $conf->ql("alter table ContactInfo add `updateTime` int(11) NOT NULL DEFAULT '0'") && $conf->ql("update ContactInfo set passwordUseTime=lastLogin where passwordUseTime=0")) { $conf->update_schema_version(94); } if ($conf->sversion == 94 && $conf->ql("alter table ContactInfo add `data` varbinary(32767) DEFAULT NULL") && $conf->ql("alter table ContactInfo add `studentYear` varbinary(4) DEFAULT NULL")) { $conf->update_schema_version(95); } if ($conf->sversion == 95 && $conf->ql("create table `RepositoryCommitSnapshot` ( `repoid` int(11) NOT NULL, `hash` binary(40) NOT NULL, `snapshot` bigint(11) NOT NULL, PRIMARY KEY (`repoid`,`hash`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8")) { $conf->update_schema_version(96); } if ($conf->sversion == 96 && $conf->ql("alter table Repository add `analyzedsnapat` bigint(11) NOT NULL DEFAULT '0'")) { $conf->update_schema_version(97); } if ($conf->sversion == 97 && $conf->ql("alter table RepositoryCommitSnapshot change `hash` `hash` varbinary(32) NOT NULL")) { $conf->update_schema_version(98); } if ($conf->sversion == 98 && $conf->ql("alter table Capability change `capabilityId` `capabilityId` int(11) NOT NULL") && update_schema_drop_keys_if_exist($conf, "Capability", ["capabilityId", "PRIMARY"]) && $conf->ql("alter table Capability add primary key (`salt`)") && $conf->ql("alter table Capability drop column `capabilityId`")) { $conf->update_schema_version(99); } if ($conf->sversion == 99 && $conf->ql("drop table if exists `CapabilityMap`")) { $conf->update_schema_version(100); } if ($conf->sversion == 100 && $conf->ql("alter table ContactImage add unique key `contactImageId` (`contactImageId`)") && update_schema_drop_keys_if_exist($conf, "ContactImage", ["contactId", "PRIMARY"]) && $conf->ql("alter table ContactImage add primary key (`contactId`,`contactImageId`)")) { $conf->update_schema_version(101); } if ($conf->sversion == 101 && $conf->ql("drop table if exists `PaperStorage`") && $conf->ql("drop table if exists `PsetGrade`")) { $conf->update_schema_version(102); } if ($conf->sversion == 102 && update_schema_drop_keys_if_exist($conf, "RepositoryGrade", ["repopset"]) && $conf->ql("alter table RepositoryGrade add primary key (`repoid`,`pset`)")) { $conf->update_schema_version(103); } if ($conf->sversion == 103 && $conf->ql("alter table Settings change `name` `name` varbinary(256) NOT NULL") && update_schema_drop_keys_if_exist($conf, "Settings", ["name"]) && $conf->ql("alter table Settings add primary key (`name`)")) { $conf->update_schema_version(104); } if ($conf->sversion == 104 && $conf->ql("alter table CommitNotes drop `nrepo`")) { $conf->update_schema_version(105); } if ($conf->sversion == 105 && $conf->ql("alter table ContactGrade add `notesversion` int(11) NOT NULL DEFAULT 1") && $conf->ql("alter table CommitNotes add `notesversion` int(11) NOT NULL DEFAULT 1")) { $conf->update_schema_version(106); } if ($conf->sversion == 106 && $conf->ql("alter table ContactGrade add `hasactiveflags` tinyint(1) NOT NULL DEFAULT 0") && $conf->ql("alter table CommitNotes add `hasactiveflags` tinyint(1) NOT NULL DEFAULT 0")) { $conf->update_schema_version(107); } if ($conf->sversion == 107 && $conf->psets() && _update_schema_regrade_flags($conf)) { $conf->update_schema_version(108); } $conf->ql("delete from Settings where name='__schema_lock'"); }
function updateSchema($Conf) { global $Opt, $OK; error_log("Note: updating schema from version " . $Conf->settings["allowPaperOption"]); if ($Conf->settings["allowPaperOption"] == 58 && $Conf->ql("alter table ContactInfo add `college` tinyint(1) NOT NULL DEFAULT '0'") && $Conf->ql("alter table ContactInfo add `extension` tinyint(1) NOT NULL DEFAULT '0'")) { update_schema_version($Conf, 59); } if ($Conf->settings["allowPaperOption"] == 59 && $Conf->ql("alter table Repository add `lastpset` int(11) NOT NULL DEFAULT '0'") && $Conf->ql("update Repository join ContactLink on (ContactLink.type=" . LINK_REPO . " and ContactLink.link=Repository.repoid) set Repository.lastpset=greatest(Repository.lastpset,ContactLink.pset)")) { update_schema_version($Conf, 60); } if ($Conf->settings["allowPaperOption"] == 60 && $Conf->ql("alter table Repository add `working` int(1) NOT NULL DEFAULT '1'")) { update_schema_version($Conf, 61); } if ($Conf->settings["allowPaperOption"] == 61 && $Conf->ql("alter table ContactInfo add `dropped` tinyint(1) NOT NULL DEFAULT '0'")) { update_schema_version($Conf, 62); } if ($Conf->settings["allowPaperOption"] == 62 && $Conf->ql("alter table ContactInfo drop column `dropped`") && $Conf->ql("alter table ContactInfo add `dropped` int(11) NOT NULL DEFAULT '0'")) { update_schema_version($Conf, 63); } if ($Conf->settings["allowPaperOption"] == 63 && $Conf->ql("alter table Repository add `snapcommitat` int(11) NOT NULL DEFAULT '0'") && $Conf->ql("alter table Repository add `snapcommitline` varchar(100)")) { update_schema_version($Conf, 64); } if ($Conf->settings["allowPaperOption"] == 64 && $Conf->ql("drop table if exists `CommitNotes`") && $Conf->ql("alter table `Repository` modify `snaphash` binary(40)") && $Conf->ql("create table `CommitNotes` ( `hash` binary(40) NOT NULL, `notes` BLOB NOT NULL, UNIQUE KEY `hash` (`hash`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8")) { update_schema_version($Conf, 65); } if ($Conf->settings["allowPaperOption"] == 65 && $Conf->ql("drop table if exists `RepositoryGrade`") && $Conf->ql("create table `RepositoryGrade` ( `repoid` int(11) NOT NULL, `pset` int(11) NOT NULL, `gradehash` binary(40), `gradercid` int(11), UNIQUE KEY `repopset` (`repoid`,`pset`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8")) { update_schema_version($Conf, 66); } if ($Conf->settings["allowPaperOption"] == 66 && $Conf->ql("alter table RepositoryGrade add `hidegrade` tinyint(1) NOT NULL DEFAULT '0'")) { update_schema_version($Conf, 67); } if ($Conf->settings["allowPaperOption"] == 67 && $Conf->ql("drop table if exists `ExecutionQueue`") && $Conf->ql("create table `ExecutionQueue` ( `queueid` int(11) NOT NULL AUTO_INCREMENT, `queueclass` varchar(20) NOT NULL, `repoid` int(11) NOT NULL, `insertat` int(11) NOT NULL, `updateat` int(11) NOT NULL, `runat` int(11) NOT NULL, `status` int(1) NOT NULL, `lockfile` varchar(1024), PRIMARY KEY (`queueid`), KEY `queueclass` (`queueclass`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8")) { update_schema_version($Conf, 68); } if ($Conf->settings["allowPaperOption"] == 68 && $Conf->ql("alter table Repository add `notes` VARBINARY(32767)") && $Conf->ql("alter table CommitNotes modify `notes` VARBINARY(32767)")) { update_schema_version($Conf, 69); } if ($Conf->settings["allowPaperOption"] == 69 && $Conf->ql("alter table CommitNotes add `haslinenotes` tinyint(1) NOT NULL DEFAULT '0'") && $Conf->ql("update CommitNotes set haslinenotes=1 where notes like '%\"linenotes\":{\"%'")) { update_schema_version($Conf, 70); } if ($Conf->settings["allowPaperOption"] == 70 && $Conf->ql("alter table ExecutionQueue add `nconcurrent` int(11)")) { update_schema_version($Conf, 71); } if ($Conf->settings["allowPaperOption"] == 71 && _update_schema_haslinenotes($Conf)) { update_schema_version($Conf, 72); } if ($Conf->settings["allowPaperOption"] == 72 && _update_schema_pset_commitnotes($Conf)) { update_schema_version($Conf, 73); } if ($Conf->settings["allowPaperOption"] == 73 && $Conf->ql("drop table if exists `ContactGrade`") && $Conf->ql("create table `ContactGrade` ( `cid` int(11) NOT NULL, `pset` int(11) NOT NULL, `gradercid` int(11), `notes` varbinary(32767), UNIQUE KEY `cidpset` (`cid`,`pset`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8")) { update_schema_version($Conf, 74); } if ($Conf->settings["allowPaperOption"] == 74 && $Conf->ql("alter table ContactGrade add `hidegrade` tinyint(1) NOT NULL DEFAULT '0'")) { update_schema_version($Conf, 75); } if ($Conf->settings["allowPaperOption"] == 75 && $Conf->ql("alter table Settings modify `data` varbinary(32767) DEFAULT NULL")) { update_schema_version($Conf, 76); } if ($Conf->settings["allowPaperOption"] == 76 && $Conf->ql("alter table Repository add `otherheads` varbinary(8192) DEFAULT NULL")) { update_schema_version($Conf, 77); } if ($Conf->settings["allowPaperOption"] == 77 && $Conf->ql("alter table Repository change `otherheads` `heads` varbinary(8192) DEFAULT NULL")) { update_schema_version($Conf, 78); } if ($Conf->settings["allowPaperOption"] == 78 && $Conf->ql("alter table CommitNotes add `repoid` int(11) NOT NULL DEFAULT '0'") && $Conf->ql("alter table CommitNotes add `nrepo` int(11) NOT NULL DEFAULT '0'")) { update_schema_version($Conf, 79); } if ($Conf->settings["allowPaperOption"] == 79 && $Conf->ql("alter table ContactInfo add `passwordTime` int(11) NOT NULL DEFAULT '0'")) { update_schema_version($Conf, 80); } if ($Conf->settings["allowPaperOption"] == 80 && $Conf->ql("alter table ExecutionQueue add `autorun` tinyint(1) NOT NULL DEFAULT '0'")) { update_schema_version($Conf, 81); } if ($Conf->settings["allowPaperOption"] == 81 && $Conf->ql("alter table ExecutionQueue add `psetid` int(11)") && $Conf->ql("alter table ExecutionQueue add `runnername` varbinary(128)")) { update_schema_version($Conf, 82); } if ($Conf->settings["allowPaperOption"] == 82 && $Conf->ql("alter table ExecutionQueue add `hash` binary(40)")) { update_schema_version($Conf, 83); } if ($Conf->settings["allowPaperOption"] == 83 && $Conf->ql("create table `RepositoryGradeRequest` ( `repoid` int(11) NOT NULL, `pset` int(11) NOT NULL, `hash` binary(40) DEFAULT NULL, `requested_at` int(11) NOT NULL, UNIQUE KEY `repopsethash` (`repoid`,`pset`,`hash`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8")) { update_schema_version($Conf, 84); } if ($Conf->settings["allowPaperOption"] == 84 && $Conf->ql("drop table if exists Partner")) { update_schema_version($Conf, 85); } if ($Conf->settings["allowPaperOption"] == 85 && $Conf->ql("drop table if exists Chair") && $Conf->ql("drop table if exists ChairAssistant") && $Conf->ql("drop table if exists PCMember")) { update_schema_version($Conf, 86); } if ($Conf->settings["allowPaperOption"] == 86 && $Conf->ql("alter table RepositoryGrade add `placeholder` tinyint(1) NOT NULL DEFAULT '0'") && $Conf->ql("alter table RepositoryGrade add `placeholder_at` int(11) DEFAULT NULL")) { update_schema_version($Conf, 87); } if ($Conf->settings["allowPaperOption"] == 87 && $Conf->ql("alter table `ContactInfo` add `anon_username` varbinary(40) DEFAULT NULL") && $Conf->ql("alter table `ContactInfo` add unique key `anon_username` (`anon_username`)")) { update_schema_version($Conf, 88); } if ($Conf->settings["allowPaperOption"] == 88 && $Conf->ql("create table `ContactImage` ( `contactImageId` int(11) NOT NULL AUTO_INCREMENT, `contactId` int(11) NOT NULL, `mimetype` varbinary(128) DEFAULT NULL, `data` varbinary(32768) DEFAULT NULL, PRIMARY KEY (`contactImageId`), KEY `contactId` (`contactId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8") && $Conf->ql("alter table `ContactInfo` add `contactImageId` int(11) DEFAULT NULL")) { update_schema_version($Conf, 89); } if ($Conf->settings["allowPaperOption"] == 89 && $Conf->ql("alter table ContactImage change `data` `data` mediumblob DEFAULT NULL")) { update_schema_version($Conf, 90); } if ($Conf->settings["allowPaperOption"] == 90 && $Conf->ql("alter table ExecutionQueue add `inputfifo` varchar(1024) DEFAULT NULL")) { update_schema_version($Conf, 91); } }