MDL-21839 backup - added new backup logs table and cleaned some anymore in use
[moodle.git] / lib / db / upgrade.php
index 0845d70..f83ffcf 100644 (file)
@@ -3881,6 +3881,52 @@ AND EXISTS (SELECT 'x'
         upgrade_main_savepoint($result, 2010043001);
     }
 
+    if ($result && $oldversion < 2010050200) {
+
+    /// Define table backup_logs to be created
+        $table = new xmldb_table('backup_logs');
+
+    /// Adding fields to table backup_logs
+        $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('loglevel', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
+        $table->add_field('message', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
+        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
+
+    /// Adding keys to table backup_logs
+        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+        $table->add_key('backupid', XMLDB_KEY_FOREIGN, array('backupid'), 'backup_controllers', array('backupid'));
+
+    /// Adding indexes to table backup_logs
+        $table->add_index('backupid-id', XMLDB_INDEX_UNIQUE, array('backupid', 'id'));
+
+    /// Conditionally launch create table for backup_logs
+        if (!$dbman->table_exists($table)) {
+            $dbman->create_table($table);
+        }
+
+    /// Drop some old backup tables, not used anymore
+
+    /// Define table backup_files to be dropped
+        $table = new xmldb_table('backup_files');
+
+    /// Conditionally launch drop table for backup_files
+        if ($dbman->table_exists($table)) {
+            $dbman->drop_table($table);
+        }
+
+    /// Define table backup_ids to be dropped
+        $table = new xmldb_table('backup_ids');
+
+    /// Conditionally launch drop table for backup_ids
+        if ($dbman->table_exists($table)) {
+            $dbman->drop_table($table);
+        }
+
+    /// Main savepoint reached
+        upgrade_main_savepoint($result, 2010050200);
+    }
+
 
     return $result;
 }