diff --git a/blocks/db/postgres7.php b/blocks/db/postgres7.php index c8bf85cee29..f44ccc86503 100644 --- a/blocks/db/postgres7.php +++ b/blocks/db/postgres7.php @@ -138,6 +138,14 @@ global $CFG; } } + if ($oldversion < 2005022401 && $result) { // Mass cleanup of bad upgrade scripts + modify_database('','CREATE INDEX prefix_block_instance_pageid_idx ON prefix_block_instance (pageid)'); + modify_database('','ALTER TABLE prefix_block_instance ALTER pagetype SET DEFAULT \'\''); + modify_database('','ALTER TABLE prefix_block_instance ALTER position SET DEFAULT \'\''); + modify_database('','ALTER TABLE prefix_block_instance ALTER pagetype SET NOT NULL'); + modify_database('','ALTER TABLE prefix_block_instance ALTER position SET NOT NULL'); + } + //Finally, return result return $result; } diff --git a/blocks/db/postgres7.sql b/blocks/db/postgres7.sql index 53598786edd..9fc97c909a9 100644 --- a/blocks/db/postgres7.sql +++ b/blocks/db/postgres7.sql @@ -10,7 +10,7 @@ CREATE TABLE prefix_block ( cron INT8 NOT NULL default '0', lastcron INT8 NOT NULL default '0', visible int NOT NULL default '1', - multiple int NOT NULL default '1' + multiple int NOT NULL default '0' ) ; CREATE TABLE prefix_block_instance ( @@ -23,5 +23,7 @@ CREATE TABLE prefix_block_instance ( visible int not null default '0', configdata text not null default '' ) ; + +CREATE INDEX prefix_block_instance_pageid_idx ON prefix_block_instance (pageid); # -------------------------------------------------------- diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index df3d5ddfe90..df63e8f2560 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -1179,6 +1179,30 @@ function main_upgrade($oldversion=0) { execute_sql("DROP TABLE {$CFG->prefix}currencies",false); // drop silently } + if ($oldversion < 2005060223) { // Mass cleanup of bad postgres upgrade scripts + execute_sql("DROP TABLE {$CFG->prefix}attendance_roll", false); // There are no attendance module anymore + modify_database('','ALTER TABLE prefix_config ALTER value SET NOT NULL'); + modify_database('','ALTER TABLE prefix_course ALTER metacourse SET NOT NULL'); + modify_database('','ALTER TABLE prefix_course ALTER theme SET NOT NULL'); + modify_database('','ALTER TABLE prefix_event ALTER repeatid SET NOT NULL'); + modify_database('','ALTER TABLE prefix_groups ALTER password SET NOT NULL'); + modify_database('','ALTER TABLE prefix_groups ALTER theme SET NOT NULL'); + modify_database('','ALTER TABLE prefix_message ALTER format SET NOT NULL'); + modify_database('','ALTER TABLE prefix_message_read ALTER format SET NOT NULL'); + modify_database('','ALTER TABLE prefix_groups ALTER theme SET NOT NULL'); + modify_database('','ALTER TABLE prefix_user ALTER aim DROP DEFAULT'); + modify_database('','ALTER TABLE prefix_user ALTER idnumber DROP DEFAULT'); + modify_database('','ALTER TABLE prefix_user ALTER msn DROP DEFAULT'); + modify_database('','ALTER TABLE prefix_user ALTER policyagreed SET NOT NULL'); + modify_database('','ALTER TABLE prefix_user ALTER skype DROP DEFAULT'); + modify_database('','ALTER TABLE prefix_user ALTER theme SET NOT NULL'); + modify_database('','ALTER TABLE prefix_user ALTER timezone SET NOT NULL'); + modify_database('','ALTER TABLE prefix_user ALTER trackforums SET NOT NULL'); + modify_database('','ALTER TABLE prefix_user ALTER yahoo DROP DEFAULT'); + modify_database('','ALTER TABLE prefix_user_students ALTER enrol SET NOT NULL'); + modify_database('','ALTER TABLE prefix_user_teachers ALTER enrol SET NOT NULL'); + } + return $result; } diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index 9b37809e1bc..1dc3cf75251 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -444,6 +444,7 @@ CREATE TABLE prefix_user_students ( CREATE UNIQUE INDEX prefix_user_students_courseuserid_uk ON prefix_user_students (course,userid); CREATE INDEX prefix_user_students_userid_idx ON prefix_user_students (userid); CREATE INDEX prefix_user_students_enrol_idx ON prefix_user_students (enrol); +CREATE INDEX prefix_user_students_timeaccess_idx ON prefix_user_students (timeaccess); CREATE TABLE prefix_user_teachers ( id SERIAL PRIMARY KEY, @@ -468,6 +469,8 @@ CREATE TABLE prefix_user_coursecreators ( userid int8 NOT NULL default '0' ); +CREATE INDEX prefix_user_coursecreators_userid_idx ON prefix_user_coursecreators (userid); + CREATE TABLE adodb_logsql ( created timestamp NOT NULL, sql0 varchar(250) NOT NULL, diff --git a/mod/assignment/db/postgres7.php b/mod/assignment/db/postgres7.php index 4380c861b51..6bbdd3140c9 100644 --- a/mod/assignment/db/postgres7.php +++ b/mod/assignment/db/postgres7.php @@ -157,6 +157,15 @@ function assignment_upgrade($oldversion) { assignment_refresh_events(); } + if ($oldversion < 2005060101) { // Mass cleanup of bad upgrade scripts + modify_database('','ALTER TABLE prefix_assignment ALTER assignmenttype SET NOT NULL'); + modify_database('','ALTER TABLE prefix_assignment ALTER emailteachers SET NOT NULL'); + modify_database('','ALTER TABLE prefix_assignment ALTER preventlate SET NOT NULL'); + modify_database('','ALTER TABLE prefix_assignment ALTER timeavailable SET NOT NULL'); + modify_database('','ALTER TABLE prefix_assignment_submissions ALTER data1 SET NOT NULL'); + modify_database('','ALTER TABLE prefix_assignment_submissions ALTER data2 SET NOT NULL'); + modify_database('','ALTER TABLE prefix_assignment_submissions ALTER format SET NOT NULL'); + } /// These lines ALWAYS need to be here at the end of this file. Don't mess with them. :-) include_once("$CFG->dirroot/mod/assignment/lib.php"); diff --git a/mod/chat/db/postgres7.php b/mod/chat/db/postgres7.php index 96caaca3538..88a89c70bfe 100644 --- a/mod/chat/db/postgres7.php +++ b/mod/chat/db/postgres7.php @@ -47,6 +47,11 @@ function chat_upgrade($oldversion) { table_column('chat_users', '', 'lang' , 'varchar', '10', '' , '' , 'not null', ''); } + if ($oldversion < 2005031001) { // Mass cleanup of bad upgrade scripts + modify_database('','ALTER TABLE prefix_chat_users ALTER course SET NOT NULL'); + modify_database('','ALTER TABLE prefix_chat_users ALTER lang SET NOT NULL'); + } + return true; } diff --git a/mod/choice/db/postgres7.php b/mod/choice/db/postgres7.php index 07952bab9cb..275c00e9de7 100644 --- a/mod/choice/db/postgres7.php +++ b/mod/choice/db/postgres7.php @@ -90,6 +90,15 @@ function choice_upgrade($oldversion) { table_column('choice', '', 'limitanswers', 'INTEGER', '2', 'unsigned', 0, 'not null', 'showunanswered'); table_column('choice_options', '', 'maxanswers', 'INTEGER', '10', 'unsigned', 0, 'null', 'text'); } + + if ($oldversion < 2005041501) { // Mass cleanup of bad upgrade scripts + modify_database('','CREATE INDEX prefix_choice_answers_choice_idx ON prefix_choice_answers (choiceid)'); + modify_database('','ALTER TABLE prefix_choice ALTER display SET NOT NULL'); + modify_database('','ALTER TABLE prefix_choice ALTER limitanswers SET NOT NULL'); + modify_database('','ALTER TABLE prefix_choice_answers ALTER choiceid SET NOT NULL'); + modify_database('','ALTER TABLE prefix_choice_answers ALTER optionid SET NOT NULL'); + } + return true; } diff --git a/mod/dialogue/db/postgres7.php b/mod/dialogue/db/postgres7.php index 7f66c0878f6..e94fd716e82 100644 --- a/mod/dialogue/db/postgres7.php +++ b/mod/dialogue/db/postgres7.php @@ -20,6 +20,11 @@ function dialogue_upgrade($oldversion) { modify_database('','CREATE INDEX prefix_dialogue_entries_userid_idx ON prefix_dialogue_entries (userid);'); } + if ($oldversion < 2005031001) { // Mass cleanup of bad postgres upgrade scripts + modify_database('','ALTER TABLE prefix_dialogue ALTER name SET DEFAULT \'\''); + modify_database('','ALTER TABLE prefix_dialogue ALTER name SET NOT NULL'); + } + $result = true; return $result; } diff --git a/mod/forum/db/postgres7.php b/mod/forum/db/postgres7.php index 78152e98d08..a489b681dcc 100644 --- a/mod/forum/db/postgres7.php +++ b/mod/forum/db/postgres7.php @@ -146,6 +146,9 @@ function forum_upgrade($oldversion) { modify_database('','CREATE INDEX prefix_forum_track_user_forum_idx ON prefix_forum_track_prefs (userid, forumid);'); } + if ($oldversion < 2005042601) { // Mass cleanup of bad postgres upgrade scripts + modify_database('','ALTER TABLE prefix_forum ALTER trackingtype SET NOT NULL'); + } return true; diff --git a/mod/glossary/db/postgres7.php b/mod/glossary/db/postgres7.php index 20d615cdf34..3c906b4c251 100644 --- a/mod/glossary/db/postgres7.php +++ b/mod/glossary/db/postgres7.php @@ -178,6 +178,10 @@ function glossary_upgrade($oldversion) { $wtm->update( 'glossary_comments','text','format',$sql ); } + if ($oldversion < 2005041901) { // Mass cleanup of bad postgres upgrade scripts + table_column('glossary','allowprintview','allowprintview','smallint','4','unsigned','1'); + } + return true; } diff --git a/mod/lesson/db/postgres7.php b/mod/lesson/db/postgres7.php index a3a17600542..c1840deb152 100644 --- a/mod/lesson/db/postgres7.php +++ b/mod/lesson/db/postgres7.php @@ -216,6 +216,36 @@ function lesson_upgrade($oldversion) { table_column('lesson_grades', 'grade', 'grade', 'real', '', 'unsigned', '0', 'not null'); } + if ($oldversion < 2005060901) { // Mass cleanup of bad postgres upgrade scripts + modify_database('','ALTER TABLE prefix_lesson ALTER bgcolor SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson ALTER custom SET NOT NULL'); + table_column('lesson','height','height','integer','16','unsigned','480'); + modify_database('','ALTER TABLE prefix_lesson ALTER highscores SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson ALTER maxattempts SET DEFAULT 5'); + table_column('lesson','maxhighscores','maxhighscores','integer','16'); + modify_database('','ALTER TABLE prefix_lesson ALTER displayleft SET NOT NULL'); + table_column('lesson','','minquestions','integer','8'); + table_column('lesson','maxtime','maxtime','integer','16'); + modify_database('','ALTER TABLE prefix_lesson ALTER ongoing SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson ALTER password SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson ALTER practice SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson ALTER review SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson ALTER slideshow SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson ALTER timed SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson ALTER tree SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson ALTER usepassword SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson ALTER width SET NOT NULL'); + table_column('lesson','width','width','integer','16','unsigned','640'); + table_column('lesson_answers','flags','flags','integer','8'); + table_column('lesson_answers','grade','grade','integer','8'); + table_column('lesson_answers','score','score','integer','16'); + modify_database('','ALTER TABLE prefix_lesson_grades ALTER grade SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson_pages ALTER display SET NOT NULL'); + modify_database('','ALTER TABLE prefix_lesson_pages ALTER layout SET NOT NULL'); + table_column('lesson_pages','qoption','qoption','integer','8'); + table_column('lesson_pages','qtype','qtype','integer','8'); + } + return true; } diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index 9cc706fbf90..95657552b9a 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -920,6 +920,44 @@ function quiz_upgrade($oldversion) { execute_sql('CREATE UNIQUE INDEX '.$CFG->prefix.'quiz_rqp_types_name_uk ON '.$CFG->prefix.'quiz_rqp_types (name);'); } + + if ($oldversion < 2005060302) { // Mass cleanup of bad postgres upgrade scripts + modify_database('','CREATE UNIQUE INDEX prefix_quiz_newest_states_attempt_idx ON prefix_quiz_newest_states (attemptid, questionid)'); + modify_database('','ALTER TABLE ONLY prefix_quiz_attemptonlast_datasets DROP CONSTRAINT prefix_quiz_category_userid_unique'); + modify_database('','ALTER TABLE ONLY prefix_quiz_attemptonlast_datasets ADD CONSTRAINT prefix_quiz_attemptonlast_datasets_category_userid UNIQUE (category, userid)'); + modify_database('','ALTER TABLE ONLY prefix_quiz_question_instances DROP CONSTRAINT prefix_quiz_question_grades_pkey'); + modify_database('','ALTER TABLE ONLY prefix_quiz_question_instances ADD CONSTRAINT prefix_quiz_question_instances_pkey PRIMARY KEY (id)'); + modify_database('','ALTER TABLE ONLY prefix_quiz_question_versions DROP CONSTRAINT prefix_quiz_question_version_pkey'); + modify_database('','ALTER TABLE ONLY prefix_quiz_question_versions ADD CONSTRAINT prefix_quiz_question_versions_pkey PRIMARY KEY (id)'); + modify_database('','ALTER TABLE ONLY prefix_quiz_states DROP CONSTRAINT prefix_quiz_responses_pkey'); + modify_database('','ALTER TABLE ONLY prefix_quiz_states ADD CONSTRAINT prefix_quiz_states_pkey PRIMARY KEY (id)'); + modify_database('','ALTER TABLE prefix_quiz ALTER decimalpoints SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz ALTER optionflags SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz ALTER penaltyscheme SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz ALTER popup SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz ALTER questionsperpage SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz ALTER review SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_answers ALTER answer SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_attempts ALTER layout SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_attempts ALTER preview SET NOT NULL'); + table_column('quiz_calculated','correctanswerformat','correctanswerformat','integer','16','unsigned','2'); + modify_database('','ALTER TABLE prefix_quiz_categories ALTER parent SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_categories ALTER sortorder SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_grades ALTER grade SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_multianswers ALTER sequence SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_numerical ALTER tolerance SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_questions ALTER hidden SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_questions ALTER length SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_questions ALTER parent SET NOT NULL'); + table_column('quiz_questions','penalty','penalty','real','','UNSIGNED','0.1'); + modify_database('','ALTER TABLE prefix_quiz_states ALTER answer SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_states ALTER event SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_states ALTER originalquestion SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_states ALTER penalty SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_states ALTER raw_grade SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_states ALTER seq_number SET NOT NULL'); + modify_database('','ALTER TABLE prefix_quiz_states ALTER timestamp SET NOT NULL'); + } return true; } diff --git a/mod/quiz/db/postgres7.sql b/mod/quiz/db/postgres7.sql index 5c85ab7baf5..ec56e529658 100644 --- a/mod/quiz/db/postgres7.sql +++ b/mod/quiz/db/postgres7.sql @@ -88,7 +88,7 @@ CREATE TABLE prefix_quiz_attempts ( timestart integer NOT NULL default '0', timefinish integer NOT NULL default '0', timemodified integer NOT NULL default '0', - layout text NOT NULL, + layout text NOT NULL default '', preview integer NOT NULL default '0' ); @@ -272,6 +272,7 @@ CREATE TABLE prefix_quiz_numerical ( tolerance varchar(255) NOT NULL default '0.0' ); +CREATE INDEX prefix_quiz_numerical_answer_idx ON prefix_quiz_numerical (answer); CREATE INDEX prefix_quiz_numerical_question_idx ON prefix_quiz_numerical (question); # -------------------------------------------------------- @@ -448,7 +449,7 @@ CREATE TABLE prefix_quiz_states ( question integer NOT NULL default '0', originalquestion integer NOT NULL default '0', seq_number integer NOT NULL default '0', - answer text NOT NULL, + answer text NOT NULL default '', timestamp integer NOT NULL default '0', event integer NOT NULL default '0', grade varchar(10) NOT NULL default '0.0', diff --git a/mod/scorm/db/postgres7.php b/mod/scorm/db/postgres7.php index 0c4f818c3ed..6314be0197e 100755 --- a/mod/scorm/db/postgres7.php +++ b/mod/scorm/db/postgres7.php @@ -174,6 +174,23 @@ function scorm_upgrade($oldversion) { table_column("scorm_scoes_track", "", "timemodified", "integer", "", "", "0", "NOT NULL", "value"); } + if ($oldversion < 2005052301) { // Mass cleanup of bad upgrade scripts + execute_sql("DROP INDEX {$CFG->prefix}scorm_scoes_track_scormid_idx", false); + execute_sql("DROP INDEX {$CFG->prefix}scorm_scoes_track_userid_idx", false); + execute_sql("DROP INDEX {$CFG->prefix}scorm_scoes_track_scoid_idx", false); + modify_database('','CREATE INDEX prefix_scorm_scoes_track_scorm_idx ON prefix_scorm_scoes_track (scormid);'); + modify_database('','CREATE INDEX prefix_scorm_scoes_track_user_idx ON prefix_scorm_scoes_track (userid);'); + modify_database('','CREATE INDEX prefix_scorm_scoes_track_sco_idx ON prefix_scorm_scoes_track (scoid);'); + execute_sql("DROP INDEX {$CFG->prefix}scorm_scoes_track_track_idx", false); + modify_database('','ALTER TABLE ONLY prefix_scorm_scoes_track DROP CONSTRAINT prefix_scorm_scoes_track_pkey'); + modify_database('','ALTER TABLE ONLY prefix_scorm_scoes_track ADD CONSTRAINT prefix_scorm_scoes_track_pkey PRIMARY KEY (id)'); + modify_database('','ALTER TABLE ONLY prefix_scorm_scoes_track ADD UNIQUE (userid, scormid, scoid, element)'); + modify_database('','ALTER TABLE prefix_scorm ALTER browsemode SET DEFAULT 0'); + modify_database('','ALTER TABLE prefix_scorm DROP version'); + table_column('scorm_scoes','datafromlms','datafromlms','VARCHAR','255','',''); + table_column('scorm_scoes','maxtimeallowed','maxtimeallowed','VARCHAR','19','',''); + } + return true; } ?> diff --git a/mod/workshop/db/postgres7.php b/mod/workshop/db/postgres7.php index 770981cc406..17feae3b1f7 100644 --- a/mod/workshop/db/postgres7.php +++ b/mod/workshop/db/postgres7.php @@ -207,6 +207,36 @@ function workshop_upgrade($oldversion) { $wtm->update( 'workshop','description','format' ); } + if ($oldversion < 2005041201) { // Mass cleanup of bad upgrade scripts + // Some of those steps might fail, it is normal. + table_column('workshop','assessmentend','assessmentend','integer','16'); + table_column('workshop','assessmentstart','assessmentstart','integer','16'); + table_column('workshop','','phase','integer','4'); + table_column('workshop','','showleaguetable','integer','8'); + table_column('workshop','releasegrades','releasegrades','integer','16'); + table_column('workshop','submissionend','submissionend','integer','16'); + table_column('workshop','submissionstart','submissionstart','integer','16'); + modify_database('','ALTER TABLE prefix_workshop ALTER teacherweight SET DEFAULT 1'); + modify_database('','ALTER TABLE prefix_workshop DROP timeagreed'); + modify_database('','ALTER TABLE prefix_workshop RENAME inalgrade TO finalgrade'); + table_column('workshop_assessments','','donotuse','integer','8'); + table_column('workshop_assessments','','timeagreed','integer','16'); + modify_database('','ALTER TABLE prefix_workshop_assessments DROP teachergraded'); + modify_database('','ALTER TABLE prefix_workshop_elements RENAME totalrassesments TO totalassessments'); + modify_database('','ALTER TABLE prefix_workshop_submissions ALTER description DROP DEFAULT'); + table_column('workshop_submissions','nassessments','nassessments','integer','16'); + table_column('workshop_elements','totalassessments','totalassessments','integer','16'); + execute_sql(" + CREATE TABLE {$CFG->prefix}workshop_rubrics ( + id SERIAL PRIMARY KEY, + workshopid int8 NOT NULL default '0', + elementno int8 NOT NULL default '0', + rubricno int4 NOT NULL default '0', + description text NOT NULL + ) + "); + } + return true; } diff --git a/mod/workshop/db/postgres7.sql b/mod/workshop/db/postgres7.sql index 83106a9d8f2..14852413904 100644 --- a/mod/workshop/db/postgres7.sql +++ b/mod/workshop/db/postgres7.sql @@ -55,8 +55,8 @@ CREATE TABLE prefix_workshop_submissions ( description TEXT, gradinggrade INT NOT NULL default '0', late INT NOT NULL DEFAULT '0', - inalgrade INT NOT NULL default '0', - nassessments INT8 NOT NULL default 0 + finalgrade INT NOT NULL default '0', + nassessments INT8 NOT NULL default '0' ); CREATE INDEX prefix_workshop_submissions_title_idx on prefix_workshop_submissions (title); @@ -108,7 +108,7 @@ CREATE TABLE prefix_workshop_elements ( maxscore INT NOT NULL default '1', weight INT4 NOT NULL default '11', stddev FLOAT NOT NULL default '0', - totalrassesments INT8 NOT NULL DEFAULT '0' + totalassessments INT8 NOT NULL DEFAULT '0' ); CREATE INDEX prefix_workshop_elements_workshopid_idx ON prefix_workshop_elements (workshopid);