Make sure all fields are equally defined in all courses (part of the process is normally done through the CONVERT TO CHARACTER SET operation, but this *might* lead to different field sizes in similar tables from different databases or on different systems

skala
Yannick Warnier 15 years ago
parent 39a73cdf7e
commit e6af93ac33
  1. 38
      main/install/migrate-db-1.8.6.2-1.8.7-post.sql
  2. 1
      main/install/migrate-db-1.8.6.2-1.8.7-pre.sql
  3. 76
      main/install/update-db-1.8.6.2-1.8.7.inc.php

@ -0,0 +1,38 @@
-- This script updates the databases structure before migrating the data from
-- version 1.8.6.2 to version 1.8.7
-- it is intended as a standalone script, however, because of the multiple
-- databases related difficulties, it should be parsed by a PHP script in
-- order to connect to and update the right databases.
-- There is one line per query, allowing the PHP function file() to read
-- all lines separately into an array. The xxMAINxx-type markers are there
-- to tell the PHP script which database we're talking about.
-- By always using the keyword "TABLE" in the queries, we should be able
-- to retrieve and modify the table name from the PHP script if needed, which
-- will allow us to deal with the unique-database-type installations
--
-- This first part is for the main database
-- xxMAINxx
ALTER TABLE course_module CHANGE name name varchar(255) NOT NULL;
ALTER TABLE sys_calendar CHANGE title title varchar(255) NOT NULL;
ALTER TABLE tag CHANGE tag tag varchar(255) NOT NULL;
-- xxSTATSxx
-- xxUSERxx
-- xxCOURSExx
ALTER TABLE quiz CHANGE title title VARCHAR(255) NOT NULL;
ALTER TABLE quiz CHANGE sound sound VARCHAR(255) DEFAULT NULL;
ALTER TABLE quiz_question CHANGE question question VARCHAR(511) NOT NULL;
ALTER TABLE tool CHANGE name name VARCHAR(255) NOT NULL;
ALTER TABLE tool CHANGE image image VARCHAR(255) default NULL;
ALTER TABLE tool CHANGE admin admin VARCHAR(255) default NULL;
ALTER TABLE tool CHANGE address address VARCHAR(255) default NULL;
ALTER TABLE calendar_event CHANGE title title VARCHAR(255) NOT NULL;
ALTER TABLE student_publication CHANGE url url VARCHAR(255) default NULL;
ALTER TABLE student_publication CHANGE title title VARCHAR(255) default NULL;
ALTER TABLE student_publication CHANGE author author VARCHAR(255) default NULL;
ALTER TABLE lp CHANGE name name varchar(255) NOT NULL;
ALTER TABLE lp_item CHANGE title varchar(511) NOT NULL;
ALTER TABLE lp_item CHANGE description varchar(511) NOT NULL default '';

@ -107,7 +107,6 @@ ALTER TABLE track_e_attempt_recording ADD INDEX (question_id);
ALTER TABLE track_e_attempt_recording ADD INDEX (session_id);
ALTER TABLE track_e_online ADD COLUMN access_url_id INT NOT NULL DEFAULT 1;
-- xxUSERxx
-- xxCOURSExx

@ -175,6 +175,33 @@ if (defined('SYSTEM_INSTALLATION')) {
Database::query($upd);
}
// Now clean the deprecated id_coach field from the session_rel_course table
$m_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-post.sql', 'main');
if (count($m_q_list) > 0) {
// Now use the $m_q_list
/**
* We connect to the right DB first to make sure we can use the queries
* without a database name
*/
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
} elseif (!in_array($dbNameForm,$dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
} else {
Database::select_db($dbNameForm);
foreach ($m_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbNameForm,$query)", 0);
} else {
$res = Database::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
}
}
}
}
}
// Get the stats queries list (s_q_list)
$s_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'stats');
if (count($s_q_list) > 0) {
@ -444,7 +471,56 @@ if (defined('SYSTEM_INSTALLATION')) {
}
}
}
// Get the courses databases queries list (c_q_list)
$c_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-post.sql', 'course');
if (count($c_q_list) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
} else {
Database::select_db($dbNameForm);
$res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
if ($res === false) { die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php'); }
if (Database::num_rows($res) > 0) {
$i = 0;
while ($row = Database::fetch_array($res)) {
$list[] = $row;
$i++;
}
foreach ($list as $row) {
// Now use the $c_q_list
/**
* We connect to the right DB first to make sure we can use the queries
* without a database name
*/
$prefix_course = $prefix;
if ($singleDbForm) {
$prefix_course = $prefix.$row['db_name']."_";
} else {
Database::select_db($row['db_name']);
}
foreach($c_q_list as $query) {
if ($singleDbForm) { //otherwise just use the main one
$query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix$2$3", $query);
}
if ($only_test) {
error_log("Database::query(".$row['db_name'].",$query)", 0);
} else {
$res = Database::query($query);
if ($log) {
error_log("In ".$row['db_name'].", executed: $query", 0);
}
}
}
}
}
}
}
} else {
echo 'You are not allowed here !';

Loading…
Cancel
Save