function backup_migrate_update_7303 in Backup and Migrate 7.3
Same name and namespace in other branches
- 8.3 backup_migrate.install \backup_migrate_update_7303()
Add a serial id field to all tables to allow them to be ctools exportable.
File
- ./
backup_migrate.install, line 808 - Install hooks for Backup and Migrate.
Code
function backup_migrate_update_7303() {
foreach (array(
'backup_migrate_sources' => 'source_id',
'backup_migrate_destinations' => 'destination_id',
'backup_migrate_schedules' => 'schedule_id',
'backup_migrate_profiles' => 'profile_id',
) as $table => $id) {
// Take the primary key status from the machine name so it can be renamed
// A serial field must be defined as a key, so make a temporary index.
// See: https://www.drupal.org/node/190027
db_add_index($table, 'temp', array(
$id,
));
db_drop_primary_key($table);
// Drop our temporary index.
db_drop_index($table, 'temp');
// Switch the name of the id to 'machine_name' to be more ctools standard.
db_change_field($table, $id, 'machine_name', array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
));
// Add a serial ID.
db_add_field($table, $id, array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
// Do not export database-only keys.
'no export' => TRUE,
), array(
'primary key' => array(
$id,
),
));
}
foreach (array(
'backup_migrate_sources',
'backup_migrate_destinations',
) as $table) {
db_change_field($table, 'type', 'subtype', array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
));
}
}