diff --git a/backup/db/postgres7.php b/backup/db/postgres7.php index 0ddafc5b7dc..3afe71539ce 100644 --- a/backup/db/postgres7.php +++ b/backup/db/postgres7.php @@ -51,24 +51,14 @@ function backup_upgrade($oldversion=0) { } if ($oldversion < 2006042801) { - modify_database('', 'ALTER TABLE prefix_backup_log - ALTER COLUMN "time" TYPE integer, - ALTER COLUMN "time" SET DEFAULT 0, - ALTER COLUMN laststarttime TYPE integer, - ALTER COLUMN laststarttime SET DEFAULT 0, - ALTER COLUMN courseid TYPE integer, - ALTER COLUMN courseid SET DEFAULT 0'); - - modify_database('', 'ALTER TABLE mdl_backup_courses - ALTER COLUMN lastendtime TYPE integer, - ALTER COLUMN lastendtime SET DEFAULT 0, - ALTER COLUMN laststarttime TYPE integer, - ALTER COLUMN laststarttime SET DEFAULT 0, - ALTER COLUMN courseid TYPE integer, - ALTER COLUMN courseid SET DEFAULT 0, - ALTER COLUMN nextstarttime TYPE integer, - ALTER COLUMN nextstarttime SET DEFAULT 0'); + table_column('backup_log', 'time', 'time', 'integer', '', '', '0'); + table_column('backup_log', 'laststarttime', 'laststarttime', 'integer', '', '', '0'); + table_column('backup_log', 'courseid', 'courseid', 'integer', '', '', '0'); + table_column('backup_courses', 'lastendtime', 'lastendtime', 'integer', '', '', '0'); + table_column('backup_courses', 'laststarttime', 'laststarttime', 'integer', '', '', '0'); + table_column('backup_courses', 'courseid', 'courseid', 'integer', '', '', '0'); + table_column('backup_courses', 'nextstarttime', 'nextstarttime', 'integer', '', '', '0'); } //Finally, return result diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index f27fe07c06a..85c23e6106a 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -1544,18 +1544,14 @@ function main_upgrade($oldversion=0) { } } - modify_database('', 'ALTER TABLE prefix_course_request - ALTER COLUMN "password" TYPE varchar(50), - ALTER COLUMN "password" SET DEFAULT \'\''); + table_column('course_request', 'password', 'password', 'varchar', '50', '', ''); - modify_database('', 'ALTER TABLE prefix_course - ALTER COLUMN currency TYPE varchar(3)'); + table_column('course', 'currency', 'currency', 'varchar', '3'); modify_database('', 'ALTER TABLE prefix_course_categories ALTER COLUMN path SET DEFAULT \'\''); - modify_database('', 'ALTER TABLE prefix_log_display - ALTER COLUMN module TYPE varchar(20)'); + table_column('log_display', 'module', 'module', 'varchar', '20'); modify_database("","DROP INDEX id_user_idx"); modify_database("","DROP INDEX post_lastmodified_idx"); diff --git a/mod/lesson/db/postgres7.php b/mod/lesson/db/postgres7.php index fad2d9b161c..2a37294c1ac 100644 --- a/mod/lesson/db/postgres7.php +++ b/mod/lesson/db/postgres7.php @@ -318,30 +318,38 @@ function lesson_upgrade($oldversion) { execute_sql('DROP TABLE '.$CFG->prefix.'lesson_essay', false); // properly set the correct default values - modify_database('', 'ALTER TABLE prefix_lesson - ALTER COLUMN activitylink TYPE int8, - ALTER COLUMN activitylink SET DEFAULT 0, - ALTER COLUMN dependency TYPE int8, - ALTER COLUMN dependency SET DEFAULT 0'); + table_column('lesson', 'activitylink', 'activitylink', 'integer', '8', '', '0'); + table_column('lesson', 'dependency', 'dependency', 'integer', '8', '', '0'); modify_database('', 'ALTER TABLE prefix_lesson_timer - ALTER COLUMN lessontime SET DEFAULT 0, - ALTER COLUMN lessonid SET DEFAULT 0, - ALTER COLUMN userid SET DEFAULT 0, + ALTER COLUMN lessontime SET DEFAULT 0'); + modify_database('', 'ALTER TABLE prefix_lesson_timer + ALTER COLUMN lessonid SET DEFAULT 0'); + modify_database('', 'ALTER TABLE prefix_lesson_timer + ALTER COLUMN userid SET DEFAULT 0'); + modify_database('', 'ALTER TABLE prefix_lesson_timer ALTER COLUMN starttime SET DEFAULT 0'); modify_database('', 'ALTER TABLE prefix_lesson_branch - ALTER COLUMN lessonid SET DEFAULT 0, - ALTER COLUMN timeseen SET DEFAULT 0, - ALTER COLUMN userid SET DEFAULT 0, - ALTER COLUMN retry SET DEFAULT 0, - ALTER COLUMN pageid SET DEFAULT 0, + ALTER COLUMN lessonid SET DEFAULT 0'); + modify_database('', 'ALTER TABLE prefix_lesson_branch + ALTER COLUMN timeseen SET DEFAULT 0'); + modify_database('', 'ALTER TABLE prefix_lesson_branch + ALTER COLUMN userid SET DEFAULT 0'); + modify_database('', 'ALTER TABLE prefix_lesson_branch + ALTER COLUMN retry SET DEFAULT 0'); + modify_database('', 'ALTER TABLE prefix_lesson_branch + ALTER COLUMN pageid SET DEFAULT 0'); + modify_database('', 'ALTER TABLE prefix_lesson_branch ALTER COLUMN flag SET DEFAULT 0'); modify_database('', 'ALTER TABLE prefix_lesson_high_scores - ALTER COLUMN nickname SET DEFAULT \'\', - ALTER COLUMN lessonid SET DEFAULT 0, - ALTER COLUMN gradeid SET DEFAULT 0, + ALTER COLUMN nickname SET DEFAULT \'\''); + modify_database('', 'ALTER TABLE prefix_lesson_high_scores + ALTER COLUMN lessonid SET DEFAULT 0'); + modify_database('', 'ALTER TABLE prefix_lesson_high_scores + ALTER COLUMN gradeid SET DEFAULT 0'); + modify_database('', 'ALTER TABLE prefix_lesson_high_scores ALTER COLUMN userid SET DEFAULT 0'); } diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index e1cf2f4aff6..719aa5b8de7 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -1216,16 +1216,10 @@ function quiz_upgrade($oldversion) { id SERIAL PRIMARY KEY, modulename varchar(20) NOT NULL default 'quiz' );"); - // create one entry for all the existing quiz attempts - modify_database ("", "INSERT INTO prefix_question_attempts (id) - SELECT uniqueid - FROM prefix_quiz_attempts;"); - } - - if ($oldversion < 2006042802) { // this block is taken from mysql.php 2005070202 // add new unique id to prepare the way for lesson module to have its own attempts table table_column('quiz_attempts', '', 'uniqueid', 'integer', '10', 'unsigned', '0', 'not null', 'id'); + // create one entry for all the existing quiz attempts // initially we can use the id as the unique id because no other modules use attempts yet. execute_sql("UPDATE {$CFG->prefix}quiz_attempts SET uniqueid = id", false); // we set $CFG->attemptuniqueid to the next available id @@ -1235,6 +1229,13 @@ function quiz_upgrade($oldversion) { modify_database('','CREATE UNIQUE INDEX prefix_quiz_attempts_uniqueid_uk ON prefix_quiz_attempts (uniqueid);'); + modify_database ("", "INSERT INTO prefix_question_attempts (id) + SELECT uniqueid + FROM prefix_quiz_attempts;"); + } + + if ($oldversion < 2006042802) { + // Copy the teacher comments from the question_essay_states table to the new // question_sessions table. @@ -1275,7 +1276,8 @@ function quiz_upgrade($oldversion) { execute_sql('DROP TABLE '.$CFG->prefix.'quiz_attemptonlast_datasets'); modify_database('', 'ALTER TABLE prefix_question - ALTER COLUMN qtype SET DEFAULT \'0\', + ALTER COLUMN qtype SET DEFAULT \'0\''); + modify_database('', 'ALTER TABLE prefix_question ALTER COLUMN version SET DEFAULT \'\''); // recreate the indexes that was not moved while quiz was transitioning to question lib diff --git a/mod/scorm/db/postgres7.php b/mod/scorm/db/postgres7.php index 9d6e4f24531..23f18ab85b1 100755 --- a/mod/scorm/db/postgres7.php +++ b/mod/scorm/db/postgres7.php @@ -232,7 +232,8 @@ function scorm_upgrade($oldversion) { if ($oldversion < 2006021401) { table_column("scorm", "", "version", "VARCHAR", "9", "", "", "NOT NULL", "reference"); - modify_database('', 'ALTER TABLE prefix_scorm ALTER COLUMN width SET DEFAULT 100, ALTER COLUMN height SET DEFAULT 500'); + modify_database('', 'ALTER TABLE prefix_scorm ALTER COLUMN width SET DEFAULT 100'); + modify_database('', 'ALTER TABLE prefix_scorm ALTER COLUMN height SET DEFAULT 500'); // there is an extra constraint key1, we should drop this modify_database('', 'ALTER TABLE prefix_scorm_scoes_track DROP CONSTRAINT prefix_scorm_scoes_track_userid_key1'); modify_database('', 'ALTER TABLE prefix_scorm_scoes_track DROP CONSTRAINT prefix_scorm_scoes_track_userid_key'); diff --git a/mod/wiki/db/postgres7.php b/mod/wiki/db/postgres7.php index b1786b637fc..da338e649f9 100644 --- a/mod/wiki/db/postgres7.php +++ b/mod/wiki/db/postgres7.php @@ -147,9 +147,12 @@ function wiki_upgrade($oldversion) { if ($oldversion < 2006042801) { modify_database('', 'ALTER TABLE prefix_wiki_pages - ALTER COLUMN content SET DEFAULT \'\', - ALTER COLUMN refs SET DEFAULT \'\', - ALTER COLUMN content DROP NOT NULL, + ALTER COLUMN content SET DEFAULT \'\''); + modify_database('', 'ALTER TABLE prefix_wiki_pages + ALTER COLUMN refs SET DEFAULT \'\''); + modify_database('', 'ALTER TABLE prefix_wiki_pages + ALTER COLUMN content DROP NOT NULL'); + modify_database('', 'ALTER TABLE prefix_wiki_pages ALTER COLUMN refs DROP NOT NULL'); }