Skip to content

Commit

Permalink
MDL-21840 backup - table for files handling on restore. Big thanks to…
Browse files Browse the repository at this point in the history
… MySQL for being so... limited?
  • Loading branch information
stronk7 committed Jul 18, 2010
1 parent c44d4ae commit 8bc29d4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
25 changes: 21 additions & 4 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20100716" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20100718" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -2639,7 +2639,7 @@
<INDEX NAME="typeitem_ix" UNIQUE="false" FIELDS="type, itemid"/>
</INDEXES>
</TABLE>
<TABLE NAME="backup_ids_template" COMMENT="To store all sort of ids along the backup process. Note this table isn't really used but its temporary counterpart." PREVIOUS="backup_controllers" NEXT="backup_logs">
<TABLE NAME="backup_ids_template" COMMENT="To store all sort of ids along the backup process. Note this table isn't really used but its temporary counterpart." PREVIOUS="backup_controllers" NEXT="backup_files_template">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="backupid"/>
<FIELD NAME="backupid" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="unique id of the backup" PREVIOUS="id" NEXT="itemname"/>
Expand All @@ -2657,7 +2657,24 @@
<INDEX NAME="backupid_parentitemid_ix" UNIQUE="false" FIELDS="backupid, itemname, parentitemid"/>
</INDEXES>
</TABLE>
<TABLE NAME="backup_logs" COMMENT="To store all the logs from backup and restore operations (by db logger)" PREVIOUS="backup_ids_template" NEXT="course_published">
<TABLE NAME="backup_files_template" COMMENT="To store files along the backup process. Note this table isn't really used but its temporary counterpart." PREVIOUS="backup_ids_template" NEXT="backup_logs">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="backupid"/>
<FIELD NAME="backupid" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="unique backup id this record corresponds to" PREVIOUS="id" NEXT="contextid"/>
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="source contextid of the file" PREVIOUS="backupid" NEXT="component"/>
<FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="contextid" NEXT="filearea"/>
<FIELD NAME="filearea" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" PREVIOUS="component" NEXT="itemid"/>
<FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="filearea" NEXT="info"/>
<FIELD NAME="info" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" COMMENT="to store the complete file record (serialized)" PREVIOUS="itemid"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="backupid_contextid_component_filearea_itemid_ix" UNIQUE="false" FIELDS="backupid, contextid, component, filearea, itemid"/>
</INDEXES>
</TABLE>
<TABLE NAME="backup_logs" COMMENT="To store all the logs from backup and restore operations (by db logger)" PREVIOUS="backup_files_template" NEXT="course_published">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="backupid"/>
<FIELD NAME="backupid" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="backupid the log record belongs to" PREVIOUS="id" NEXT="loglevel"/>
Expand Down Expand Up @@ -2689,4 +2706,4 @@
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
29 changes: 29 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4834,6 +4834,35 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2010071701);
}

if ($oldversion < 2010071800) {

// Define table backup_files_template to be created
$table = new xmldb_table('backup_files_template');

// Adding fields to table backup_files_template
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
$table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
$table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
$table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('info', XMLDB_TYPE_TEXT, 'medium', null, null, null, null);

// Adding keys to table backup_files_template
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

// Adding indexes to table backup_files_template
$table->add_index('backupid_contextid_component_filearea_itemid_ix', XMLDB_INDEX_NOTUNIQUE, array('backupid', 'contextid', 'component', 'filearea', 'itemid'));

// Conditionally launch create table for backup_files_template
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}

// Main savepoint reached
upgrade_main_savepoint(true, 2010071800);
}

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)

$version = 2010071701; // YYYYMMDD = date of the last version bump
$version = 2010071800; // YYYYMMDD = date of the last version bump
// XX = daily increments

$release = '2.0 Preview 4+ (Build: 20100718)'; // Human-friendly version name
Expand Down

0 comments on commit 8bc29d4

Please sign in to comment.